7 Responsive design

 

This chapter covers

  • Building web pages for multiple devices and screen sizes
  • Using media queries to alter your design based on viewport size
  • Taking a mobile-first approach when styling a page
  • Using responsive images

In our modern world, the web is everywhere. We use it on our desktop in our office. We lie in bed surfing on our tablet. It’s even on some of our television screens in the living room. And we carry it everywhere with us on our smartphones. The web platform of HTML, CSS, and JavaScript is a universal ecosystem, unlike anything that has come before.

This poses an interesting problem for us as web developers: How do we design our site so it’s usable and appealing on any device our users might use to access it? Initially, many developers approached this problem by creating two websites: desktop and mobile. The server then redirected mobile devices from http://www.wombatcoffee.com to http://m.wombatcoffee.com. This mobile website would usually offer a more minimal experience and a streamlined design for smaller screens.

7.1 Mobile first

7.1.1 Creating a mobile menu

7.1.2 Adding the viewport meta tag

7.2 Media queries

7.2.1 Understanding types of media queries

7.2.2 Adding breakpoints to the page

7.2.3 Adding responsive columns

7.3 Fluid layouts

7.3.1 Adding styles for a large viewport

7.3.2 Dealing with tables

7.4 Responsive images

7.4.1 Using multiple images for different viewport sizes

7.4.2 Using srcset to serve the correct image

Summary