CSE326 Examples77 topics · one complete example each

All topics › Unit 3 · Cascading Style Sheets

Topic 37 · 37 of 43

Responsive Web Design

All in one: every responsive tool, side by side

What this example compares
  • The viewport tag: no tag (the phone acts 980px wide) vs <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • Media query conditions: (min-width: 700px) vs (max-width: 699px) vs and vs (orientation: landscape) vs print
  • Mobile-first vs desktop-first: default + min-width vs default + max-width that undoes it
  • Breakpoints: (no query) vs 600px vs 900px vs 1200px
  • No breakpoint: repeat(auto-fit, minmax(..., 1fr)) vs flex-wrap: wrap + flex: 1 1 ...
  • Flexible pictures: no rule vs max-width: 100% vs max-width: 100%; height: auto (and a video)
  • The page wrapper: width: 1100px vs max-width: 1100px vs margin: 0 auto vs padding: 0 16px
  • Text size: 2rem vs 5vw vs clamp(1.75rem, 5vw, 3rem)
  • Hiding: display: none on a decoration (right) vs on the contact details (wrong)
  • All together: the project page with one media query, on a phone and on a laptop
  • Testing: F12 + Ctrl+Shift+M vs 375px vs a real phone vs 200% zoom

Point at any word in the code to see what it means (tap on a phone); click a word to keep its meaning on screen. Read the comment above each numbered panel, press Run, then Edit & experiment to try the TRY lines yourself.

The complete code

Loading the example…

What you should see

You should see eleven panels. In panel 1 phone A is a tiny, unreadable miniature whose box is green ("500px or wider"), while phone B shows readable text and an orange box ("narrow screen"). In panel 2 the phone lights only lamp 2, the tablet lamps 1, 3 and 4, and the laptop lamps 1 and 4; lamp 5 (print) is off everywhere, and the yellow line under the lamps reports the width of your own Run frame. Panel 3 shows A, B, C stacked on both phones and in a row on both laptops. Panel 4 shows one column at 400px, two columns at 700px, a sidebar at 1000px and a centred, capped page at 1400px. In panel 5 the grid's 4th tile stays one column wide while the flex 4th tile stretches across the line. Panel 6 shows a picture that sticks out, one that is squashed, and one (and a video) that fit. In panel 7 only the first phone runs off its screen, the third and fourth monitors are centred, and the fourth phone's text stands clear of the edges. In panel 8 the 5vw heading is the smallest on the phone but the biggest on the laptop. In panel 9 the right phone keeps the e-mail address and the wrong phone keeps the picture. Panel 10 shows the project page stacked on the phone and with a sidebar on the laptop. There is no JavaScript, so nothing is printed in a Console.

Quick check: in panel 2, why is lamp 2 OFF on the tablet but lamp 4 ON?

Lamp 2 is (max-width: 699px): it is true only up to 699px, and the tablet is 800px wide. Lamp 4 is (orientation: landscape): it is true whenever the screen is wider than it is tall, and the tablet is 800 × 560. Width and orientation are separate conditions, so one screen can make one false and the other true.