css · level 2 · unit 4 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
and follow the screen; follows the text.
The is the part of the window that shows the page. 1vw is 1% of its width and 1vh is 1% of its height, so height: 60vh fills six tenths of the screen.
em is different: 1em is the element's own font size. On a button with font-size: 20px, padding: 0.5em comes to 10px. Make the text bigger and the padding grows with it.
A good habit: rem for most sizes, em for space that should match the text, and vw or vh for things that follow the screen.
<div class="welcome">
<h1>Hello!</h1>
<p>Scroll down for today's games.</p>
</div> .welcome {
height: 60vh;
padding: 1em;
font-size: 24px;
background-color: lightgreen;
} Press show my page to see it here.
The panel is 60vh tall on every screen, and its padding is 1em, which here is 24px.
guess first
Padding in em. How much padding does the button get?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<button class="btn">Order now</button> .btn {
font-size: 20px;
padding: 0.5em 1em;
}
your turn
Your turn. Padding that follows the text.
Give the tag padding in em, so it grows with the text. Choose any amount from 0.25em to 1em.
the page you’re styling
<span class="tag">Vegan</span>your css
Press show my page to see it here.
- the padding is in
emnot checked yet - the padding is 0.25em to 1emnot checked yet
fix it
The welcome panel should fill the screen's height. Fix it!
the page you’re styling
<div class="hero">
<h1>Welcome to the zoo</h1>
</div>your css
Press show my page to see it here.
- the panel is as tall as the screennot checked yet
100%of what? Think about how tall the panel's parent is.- The body is only as tall as its content, so 100% of it is no help.
- Use
100vh, the full height of the viewport, then press run.
nailed it
your sizes follow the screen and the text. :D
1vwand1vhare 1% of the viewport's width and height.1emis the element's own font size.height: 100%needs a parent with a height;100vhdoes not.
new words in your collection
- viewport
- vw
- vh
- em
This lesson isn’t saved. A free account remembers every lesson you finish.