🌐CSS Box Model
Also known as Box Model, Margin and Padding, box-sizing
Each part of a page is a box. Space and a border wrap around what is in it.
Think of it like
Think of it like a framed photo on a wall. The photo, the mat around it, the frame, then the gap to the next frame.
Example
Emma sets a box to 300px wide with 20px of padding. It shows up 340px wide, until she adds box-sizing: border-box.
Why it matters
Every gap and every size on a page comes from these four layers. Knowing them ends most layout puzzles.
Definition
Example code
css
* {
box-sizing: border-box;
}Common mistake
Key takeaways
- 1Four layers. Content, padding, border, margin.
- 2Inside or outside. Padding inside the border, margin outside.
- 3Watch the width. border-box makes sizes add up simply.