CSS essentialsFoundations
The box model
6 min lesson
Every element is laid out as a box: content, padding, border, and margin. Padding adds room inside the border; margin creates space outside it.
Keep in mind
Setting box-sizing to border-box makes declared widths include padding and border, which is easier to reason about.
styles.css
* {
box-sizing: border-box;
}
.card {
width: 18rem;
padding: 1.25rem;
border: 1px solid #d9e1dd;
margin-block: 1rem;
}What happens: A card whose width includes its padding and border.