Lesson 1 · Unit 04
Responsive rules
The viewport tag, media queries, and sizes that flex
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?
<!doctype html>
<html>
<head>
<title>Tea shop</title>
</head>
<body>
<p>Fresh tea, posted daily.</p>
</body>
</html>Correct answer
A viewport meta tag in the head
Why
Phones assume a page was made for desktops and lay it out about 980px wide unless the page says otherwise. A media query would not help: the browser believes it is 980px wide, so queries for small screens never match.
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.
<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.
.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.