css · level 2 · unit 7 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
turns a sudden change into a smooth one.
Change a colour on :hover and it snaps across instantly. A transition makes the change smooth instead, like a light on a dimmer switch.
Put transition on the normal rule, not the hover rule: transition: background-color 0.3s;. It names the property to smooth out, then the , which is how long the change takes.
Durations come in seconds, 0.3s, or milliseconds, 300ms: the same thing. Keep them short. Anything over half a second starts to feel slow.
<button class="btn">Book a table</button> .btn {
padding: 12px 20px;
color: white;
background-color: royalblue;
transition: background-color 0.3s;
}
.btn:hover {
background-color: navy;
} Press show my page to see it here.
Point at the button, then move away. It fades both ways.
guess first
The transition sits on the hover rule. What happens when you move away?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<button class="btn">Order</button> .btn {
color: white;
background-color: royalblue;
}
.btn:hover {
background-color: navy;
transition: background-color 1s;
}
your turn
Your turn. Smooth the card.
Give the card a transition on background-color, with a duration from 0.2s to 0.5s.
the page you’re styling
<div class="card">
<h2>Pottery class</h2>
<p>Tuesdays at seven.</p>
</div>your css
Press show my page to see it here.
- the background change is smoothnot checked yet
- it takes from 0.2s to 0.5snot checked yet
fix it
The colour still snaps. Fix it!
the page you’re styling
<a class="link" href="https://example.com/tickets">Get tickets</a>your css
Press show my page to see it here.
- the colour change is smoothnot checked yet
- it takes 300msnot checked yet
- The browser skipped the transition. Look at the number.
- A duration needs a unit:
sfor seconds ormsfor milliseconds. - Write
300msin place of300, then press run.
nailed it
your changes glide instead of snapping. :D
transitionsmooths a change over a duration.- Put it on the normal rule, not the hover rule.
- Durations need a unit:
sorms.
new words in your collection
- transition
- duration
This lesson isn’t saved. A free account remembers every lesson you finish.