Bitpath

Lesson 1 · Unit 04

Responsive rules

The viewport tag, media queries, and sizes that flex

13 exercisesabout 3 min

What you practise

  • The viewport meta tag, media queries, mobile first, fluid sizes with clamp(), images that fit

Try a question from this lesson

Pick one

On a phone 400px wide this page comes out tiny: the browser laid it out 980px wide, then shrank it to fit. What is missing?

HTML
<!doctype html>
<html>
  <head>
    <title>Tea shop</title>
  </head>
  <body>
    <p>Fresh tea, posted daily.</p>
  </body>
</html>

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

The viewport tag

This one line in the <head> tells a phone: lay the page out at the real width of the screen, and do not zoom out.

Every responsive page starts with it. Without it, the layout width is a made-up desktop size and nothing you write for narrow screens applies.

HTML
<head>
  <meta name="viewport"
        content="width=device-width,
                 initial-scale=1">
</head>

Concept

Mobile first

Write the narrow layout as plain rules: on a phone, one column is usually right. Then add min-width queries, smallest first, each changing only what a wider screen needs.

A query switches its rules on or off. It adds no specificity, so when several match, the later one wins. That is why their order matters.

CSS
.card { width: 100%; }

@media (min-width: 600px) {
  .card { width: 50%; }
}

10 more exercises in the app

  • 2× multiple choice
  • 4× type the answer
  • 1× true or false
  • 1× fill the blanks
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy