Coding Lesson
CSS: Appearance
Make your page work on a phone
Your goal: Finish and test your styled hobby page.
Learn
A responsive page adapts to a narrow screen without forcing readers to pan sideways or zoom out to read. You will test your own styled hobby page, keep its content flexible, and fix the element that causes any overflow. A short starter alone cannot test all the parts of your project.
Walkthrough: why the code works
Continue the page you actually built
Open your saved hobby page from the earlier lessons. The supplied starter is only a minimal practice shell. If using it, add two sections and some realistic text first. Include an image only when you have a working one, so you can check how it behaves.
Keep the viewport setting
The starter already includes the viewport meta element in head. It helps mobile browsers use the device width for layout instead of shrinking a wide virtual page. It does not repair fixed-width content by itself.
<meta name="viewport" content="width=device-width, initial-scale=1">Limit width without forcing it
A block such as main normally fits its available space. max-width: 800px stops it growing too wide but still lets it become narrower. margin: auto centres it when spare space exists. Page padding keeps text away from the edges.
body { margin: 0; padding: 20px; font: 1rem/1.6 Arial, sans-serif; } main { max-width: 800px; margin: auto; } img { max-width: 100%; height: auto; }Let images and columns adapt
max-width: 100% stops an image exceeding its container. height: auto preserves its proportions. If you kept lesson 10’s Grid layout, retain its single-column default and wider-screen media query. Do not add a fixed height to paragraphs or cards: wrapped text needs extra vertical space.
Test, diagnose and save
Check a narrow viewport around 375 CSS pixels, a wider window, and 200% zoom. Read paragraphs and use the links and buttons. If the page scrolls sideways, inspect the widest element: a fixed width, a large image or a long unbroken string may be responsible. Fix that cause rather than hiding all overflow. Download the tested version.
Expected results
On a narrow screen, the text wraps inside the page and remains comfortably readable.
Images keep their shape and fit their containers.
Any two-column layout stacks when its media query no longer applies, and essential content is not clipped.
Common mistakes and how to fix them
The page is tiny on a phone: Check that the viewport meta element is in head and that a large fixed-width wrapper is not forcing a desktop layout.
A picture looks stretched: Avoid conflicting fixed width and height rules. Use height: auto with the width constraint.
Sideways scrolling was hidden rather than fixed: Remove the clipping rule and find the overflowing element. Hiding overflow can make text or controls unreachable.
View starter code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My hobby page</title>
<style>
body {
font: 1rem/1.6 Arial, sans-serif;
}
</style>
</head>
<body>
<h1>My hobby</h1>
<p>I enjoy learning something new.</p>
<main>
<p>Add your hobby sections here.</p>
</main>
</body>
</html>Your challenge
Apply what you learned to your hobby page. Test a narrow window and download the styled version.
Keep developing your hobby page: Download HTML before leaving the sandbox, then choose Open HTML file when returning to your project. Load saved draft restores only this lesson’s draft in this browser.
Practise in the sandboxShow a hint
Use max-width instead of a fixed page width. Keep the viewport meta tag.
Show a sample answer
Try the challenge first. This is one possible answer or a snippet to adapt.
body {
margin: 0;
padding: 20px;
font: 1rem/1.6 Arial, sans-serif;
}
main {
max-width: 800px;
margin: auto;
}
img {
max-width: 100%;
height: auto;
}Check your work
At a phone-sized width, text is readable, images fit and no horizontal scrolling is needed.
Completion is your own check, not an automatic grade.
