The box model
Content, padding, border and margin — the four boxes behind every element.
What you will be able to do
- Measure an element's size
- Use border-box sizing
- Collapse margins intentionally
Every element is a rectangle made of four layers. Confusion about layout usually comes from forgetting one of them.
*, *::before, *::after {
box-sizing: border-box;
}
.card {
width: 320px;
padding: 24px;
border: 1px solid #e7e0d6;
margin-block: 16px;
}Your turn
EasyFix the overflowing card
A 400px card with 32px padding overflows its 400px container. Add the global border-box reset.
CSS · starter
.card {
width: 400px;
padding: 32px;
}Check your understanding before moving on.
Knowledge checkQuestion 1
With box-sizing: border-box, what does width: 300px include?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.