Animate to height/width auto (without hacks)
Only three lines of code and you have a smooth transition to height: auto
& {
interpolate-size: allow-keywords;
}
p {
transition: 1s;
}
p:not(:hover) {
height: 5lh;
}
The interpolate-size: allow-keywords
is doing all the magic. Read Animate to height: auto; (and other intrinsic sizing keywords) in CSS for more detail.
Try the below using the lastest version of chrome:
See the Pen Animating to height: auto by Temani Afif (@t_afif) on CodePen.
More CSS Tips
- Puzzle shapes using CSS mask A few lines of code to craft different puzzle shapes.
- The Filling CSS loaders Collection 20 CSS-only single element loaders.
- Update CSS variables using range slider A CSS-only way to update CSS variables in real time using range slider.
- Progress element with a tooltip Adding a tooltip to the native progress element showing the precentage of progress.