Students see every element as a box of content, padding, border and margin, and find out that width sets only the content, so padding and border make the box wider.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 10 min · Investigate 12 min · Mix it up 4 min · Modify 8 min · Make 11 min
Read the unit primer "CSS in 5 minutes" (the box paragraph), then make the Make task's card yourself and point at it with Box model on.
The Box model view (a button in the HTML playground) works like the browser's developer tools: point at any box to see its margin (orange), border (gold), padding (green) and content (blue), with sizes. It never changes the page. The Boxes button is different: it adds space to show nesting, so use Box model in this lesson.
The one idea: width sets the content only. The box on the page is the width plus the padding and border on both sides. Real sites often set box-sizing: border-box so that width includes padding and border; mention it once, after students are comfortable with the sums.
padding: 20 with no unit; the browser ignores it without an error.On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Swap cards with a partner. Without running them, add up the width of the card on paper, then point at it with Box model to check.
Listen for students who add only one side of the padding or border. Ask how many sides a box has left and right.
Working out that padding and border add to the width. Ask for the sum on paper first (200 + 20 + 20 + 5 + 5), then check it with Box model.
| What you will see | A question to ask | The fix |
|---|---|---|
| Padding or margin does nothing, and there is no error. | Does the value have a unit, such as px? | Write padding: 20px; not padding: 20; |
| The card is wider than the width they set. | What else is added to the width? | Padding and border are added on both sides; take them into account, or reduce the width. |
| The cards touch each other. | Which property makes space outside a box? | Add margin to the card's rule (padding is inside the border). |
One possible solution for each task. Other correct programs are fine.
<style>
.card {
border: 2px solid navy;
padding: 12px;
}
</style>
<div class="card">Owls: 12 points</div>
<div class="card">Hawks: 9 points</div>
<style>
.card {
border: 2px solid navy;
padding: 12px;
margin: 16px;
}
</style>
<div class="card">Owls: 12 points</div>
<div class="card">Hawks: 9 points</div>
<style>
.card {
border: 2px solid navy;
padding: 12px;
margin: 16px;
width: 200px;
}
</style>
<div class="card">Owls: 12 points</div>
<div class="card">Hawks: 9 points</div>
<style>
.card {
width: 220px;
padding: 16px;
border: 4px solid darkorange;
margin: 16px;
background-color: lightyellow;
}
</style>
<div class="card">
<h2>Soccer club</h2>
<img src="ball.svg" alt="A soccer ball" width="80">
<p>Thursdays after school on the top oval.</p>
</div>
Stretch: Use different padding on each side (padding: 10px 30px;) and predict the width before pointing at it. Then add border-radius: 12px; for rounded corners.
Support: Give students the Modify starter with Box model on and ask them only to add padding, then margin, pointing at the card after each.
A box has width: 300px; padding: 10px; border: 2px solid; How wide is it on the page, and why?
324 pixels: 300 for the content, plus 10 padding on each side (20) and 2 border on each side (4).
Next lesson is a review of the unit on a whole newsletter page: reading a longer stylesheet and turning the articles into cards. Class idea: measure a real website's buttons with the browser's developer tools (right-click, Inspect).