Every element on a page is a rectangular box. Around its content, a box has three layers:
- Padding: space inside the box, between the content and the border. The background color fills it.
- Border: a line around the padding.
- Margin: space outside the border, pushing other elements away. It is always transparent.
.card {
padding: 20px;
border: 2px solid black;
margin: 30px;
}
Borders
border takes three values in one go: thickness, style and color. Common styles are solid, dashed and dotted.
Round the corners of a box with border-radius:
.card {
border-radius: 12px;
}
One side at a time
Each layer can be set per side: margin-top, padding-left, border-bottom and so on. There is also a shorthand with two values, where the first is top and bottom and the second is left and right:
padding: 10px 24px;
Padding or margin?
If you want more room inside the colored area, use padding. If you want to move the whole box away from its neighbors, use margin.
Your Task
- Give
.carda padding of20pxon all sides. - Give it a border that is
2pxthick,solid, in any color. - Round its corners with a
border-radiusof12px. - Add a
margin-bottomof24pxso the two cards do not touch.
- The cards have
20pxof padding on every side - The cards have a
2pxsolid border all the way around - The corners are rounded by
12px - The cards have a bottom margin of
24px
Lesson complete!
Next Lesson: Width and Centering