🖨 Print / Save PDF
← Lesson
BitWith
Bite
Full-Stack · Quick Reference
Lesson 8 — Box Model
Cheat Sheet
Full-Stack
In one line:
Every element is a box made of content, padding, border, and margin — box-sizing:border-box makes width calculations sane.
The Four Layers
1
Content.
The actual text/media.
2
Padding.
Space inside the border.
3
Border.
The line around the padding.
4
Margin.
Space outside the border, between elements.
5
box-sizing: border-box.
Width includes padding+border, not just content.
The Fix Everyone Uses
*, *::before, *::after { box-sizing: border-box; }
width:200px + padding:20px (content-box)
Rendered width: 240px
width:200px + padding:20px (border-box)
Rendered width: 200px