Coding Lesson
CSS: Appearance
A simple page layout
Your goal: Arrange two related sections.
Learn
A layout should adapt to the space available to it. This lesson starts with two sections stacked vertically, then uses CSS Grid and a media query to place them side by side when the preview is wide enough. The HTML reading order stays the same.
Walkthrough: why the code works
Find the parent and its children
The main element has class="sections" and contains two section elements: Equipment and Tips. The .sections rule sets display: grid on their parent. Its direct children become grid items. The section rule gives each child a blue background and internal padding.
Observe the narrow layout first
The starter does not declare multiple columns, so the two sections stack. gap: 20px separates grid items. It is already present; do not add margin to every child just to create the same gap. Run the starter and identify padding inside each section versus the gap between them.
Add the wider-screen rule
Place this media query after the existing CSS rules inside style. min-width: 650px means the rule applies at 650 CSS pixels and above, including exactly 650px. Keep the original display and gap rules outside it.
@media (min-width: 650px) { .sections { grid-template-columns: repeat(2, minmax(0, 1fr)); } }Understand the two columns
repeat(2, ...) creates two tracks. Each 1fr receives an equal share of the available space after the gap. minmax(0, 1fr) allows a track to shrink below its content’s usual minimum width, although an unbroken URL or oversized image can still need its own overflow handling.
Test the actual preview width
In the Sandbox, the media query uses the width of the preview frame, not the full monitor. Open a downloaded copy in a normal browser tab if you need more room. Test below 650px and above it. Equipment should come before Tips in both layouts. Use the same pattern for your own two related hobby sections.
Expected results
Below 650 CSS pixels, the sections stack with a 20px gap.
At 650px and above, the sections occupy two equal grid columns with space between them.
The content order stays Equipment then Tips; only the arrangement changes.
Common mistakes and how to fix them
The page never forms two columns: Check the preview width and confirm the .sections selector matches class="sections" on main.
The sections have Grid but are still stacked: Apply display: grid and grid-template-columns to their shared parent, not separately to each section.
Rules after the query stop working: The query needs one closing brace for .sections and another for @media. Check both.
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>
.sections {
display: grid;
gap: 20px;
}
section {
background: #dbeafe;
padding: 20px;
}
</style>
</head>
<body>
<h1>My hobby</h1>
<main class="sections">
<section>
<h2>Equipment</h2>
<p>What I use.</p>
</section>
<section>
<h2>Tips</h2>
<p>How I practise.</p>
</section>
</main>
</body>
</html>Your challenge
Make the sections form two equal columns at widths of 650px and above. Keep a visible gap and a single column below that width.
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 grid-template-columns: repeat(2, minmax(0, 1fr)); inside the media query.
Show a sample answer
Try the challenge first. This is one possible answer or a snippet to adapt.
.sections {
display: grid;
gap: 20px;
}
@media (min-width: 650px) {
.sections {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}Check your work
The sections sit side by side on a wide screen, with a visible gap.
Completion is your own check, not an automatic grade.
