Transforms & transitions
CSS effects
CSS has a bunch off different effect properties built-in, with slightly different features.
We’ll look at the two easier ones this week: transform
& transition
transform
Visual effects that can be applied to any HTML element; but, by themselves, they are not interactive.
- Rotations
- Skewing
- Scaling up or down
- etc.
HTML
<div class="violet"></div>
<div class="purple"></div>
<div class="green"></div>
CSS .violet {
transform: rotate(33deg);
}
.purple {
transform: skew(24deg);
}
.green {
transform: scale(1.5) rotate(-6deg);
}
transition
Transitions are user initiated easing effects. When a user interacts with an element we can apply some kind of easing-like animation.
- Triggered when a property changes on an element
- Must always be written on the default state
- Can animate any element that’s a number:
padding
,color
,transform
, etc.
HTML
<a class="btn" href="#">T-Rex!</a>
CSS .btn {
background-color: #5e54af;
transition: all 200ms linear;
}
.btn:hover {
background-color: #3c3670;
}
Videos & tutorials
CSS animations & effects ➔ CSS animations & effects cheat sheet ➔