css · level 1 · unit 5 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Every element is a box, and adds room inside.
The browser draws every element as a box. The names its layers, like an onion: content in the middle, then padding, then a border, then a margin on the outside.
Padding is the space between the content and the edge of the box. The background fills it, so padding makes a coloured box look roomy instead of cramped.
padding: 20px adds room on all four sides. padding-top, padding-right, padding-bottom and padding-left set one side each.
<div class="note">Back in 5 minutes</div> .note {
background-color: khaki;
padding: 20px;
} Press show my page to see it here.
<div> is a plain box with no look of its own, handy for grouping things.
guess first
Padding on one side. Where does the room go?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<p class="tag">Sale</p> .tag {
background-color: pink;
padding-left: 40px;
}
your turn
Your turn. Make a roomy badge.
Give the badge a background colour and between 10px and 30px of padding on every side.
the page you’re styling
<div class="badge">Star reader</div>your css
Press show my page to see it here.
- the badge has a background colournot checked yet
- there is 10px to 30px abovenot checked yet
- there is 10px to 30px at the sidenot checked yet
fix it
The card is still cramped. Can you fix it?
the page you’re styling
<div class="card">Happy birthday, Gran!</div>your css
Press show my page to see it here.
- the card has 16px of paddingnot checked yet
- The padding did not appear. Read the property name slowly.
- There is a letter missing from the property name.
- Change
padingtopadding, then press run.
nailed it
you gave your boxes room inside. :D
- Every element is a box: content, padding, border, margin.
paddingadds room inside, and the background fills it.padding-topand friends set one side at a time.
new words in your collection
- box model
- padding
This lesson isn’t saved. A free account remembers every lesson you finish.