css · level 3 · unit 5 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A moves how a box is drawn, not where it sits.
Margins move a box and push its neighbours along. A transform is different: it changes how the box is drawn, while the layout keeps its old place. Its neighbours never move.
slides a box. The first value is across, the second is down: translate: 10px -4px moves it 10px right and 4px up. Negative values go left and up.
Nothing else has to be laid out again, so transforms are smooth to animate. That is why buttons lift on hover with translate, not margin.
<button class="btn">Lift me</button>
<p>This paragraph never moves.</p> .btn {
padding: 10px 18px;
}
.btn:hover {
translate: 0 -4px;
} Press show my page to see it here.
Hover over the button: it lifts, and the paragraph stays exactly where it was.
guess first
The badge moves. What happens to the text beside it?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<p><span class="badge">New</span> The autumn range is in.</p> .badge {
display: inline-block;
translate: 0 -6px;
background-color: gold;
}
your turn
Your turn. Nudge the notification dot.
Fill in translate so the dot moves 6px right and 6px up, onto the corner of the bell.
the page you’re styling
<span class="bell">Bell<span class="dot"></span></span>your css
Press show my page to see it here.
- the dot moves 6px right and upnot checked yet
fix it
The card slid left instead of up. Can you fix it?
the page you’re styling
<a class="card" href="https://example.com/guide">Read the guide</a>your css
Press show my page to see it here.
- the card lifts 4px upnot checked yet
- The card moved, but sideways. How many values does
translatehave here? - With one value,
translateonly moves across. The up and down value comes second. - Write
translate: 0 -4px;, then press run.
nailed it
you moved a box without moving the page. :D
- A transform changes how a box is drawn, not the layout.
translate: x ymoves across, then down.- Negative values go left and up.
new words in your collection
- transform
- translate
This lesson isn’t saved. A free account remembers every lesson you finish.