The box model, sizing, and spacing
Build predictable lesson cards and distinguish content, padding, border, and margin.
- Difficulty
- beginner
- Time
- 40 minutes
- Last verified
- 9/21/2026
What you will build
Build predictable lesson cards and distinguish content, padding, border, and margin.
Understand the idea first
Border-box includes padding and border in the declared size.
Build it step by step
*,
*::before,
*::after {
box-sizing: border-box;
}
.lesson-card {
max-width: 42rem;
padding: 1.5rem;
border: 1px solid #fed7aa;
margin-block: 1rem;
border-radius: 0.75rem;
}- Add
lesson-cardto one section. - Compare computed width before and after global border-box sizing.
- Change padding and margin separately.
- Use max-width and narrow the viewport to confirm no overflow.
Read the important lines
- Border-box includes padding and border in the declared size.
- Logical properties adapt to writing modes.
- A spacing rhythm is easier to maintain than random values.
Common mistakes and what to check
| Symptom | What to check |
|---|---|
| Card exceeds its width | Content-box adds padding and border. |
| Text touches the edge | Add padding, not literal spaces. |
Practice without copying
Create two equal cards with consistent padding and a 1rem gap; record the computed width.
Check the answer after you try
Both cards share one class rather than duplicated rules.
Completion check
- I produced the required visible result
- I can explain the input, processing, and output
- I tested normal, edge, and failure cases