Technology News

CSS Grid Can Do Auto Height Transitions

Bonafide CSS trick alert! Nelson Menezes figured out a new way (that only works in Firefox for now) that is awfully clever.

Perhaps you know that CSS cannot animate to auto dimensions, which is super unfortunate. Animating from zero to “whatever is necessary” would be very helpful very often. We’ve documented the available techniques. They boil down to:

  • Animate the max-height to some more than you need value, which makes timing easing imprecise and janky.
  • Use JavaScript to measure the final size and animate to that, which means… using JavaScript.

Nelson’s technique is neither of those, nor some transform-based way with visual awkwardness. This technique uses CSS Grid at its core…

.expander { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 1s;
} .expander.expanded { grid-template-rows: 1fr;
}

Unbelievably, in Firefox, that transitions content inside that area between 0 and the natural height of the content. There is only a little more to it, like hiding overflow and visibility to make it look right while maintaining accessibility:

That’s wonderful. Let’s get some stars on this issue and maybe Chrome will pick it up. But of course, even better would be if auto height transitions just started working. I can’t imagine that’s totally outside the realm of possibility.

A Beginner’s Guide to the Parse Platform on Back4App
Creating A Social Media Funnel: A Step-By-Step Guide

Related Articles

He Sees You When You’re Sleeping…

He Sees You When You're Sleeping...
The holidays are upon us, and it’s time to ask some SERIOUS questions:Why do we allow Santa to spy on us through the year to see if we’re being good…

5 SOP Examples for your HR department

5 SOP Examples for your HR department
In a survey of over 10,000 workers in various knowledge-based jobs, Asana’s “Anatomy of Work” study found that busy employees weren’t always busy doing work that would have an impact.…

Web Frameworks: Why You Don’t Always Need Them

web-frameworks-why-you-dont-always-need-them
Richard MacManus Richard is senior editor at The New Stack and writes a weekly column about web and application development trends. Previously he founded ReadWriteWeb in 2003 and built it…

WordPress 6.8 Beta 3

WordPress 6.8 Beta 3
WordPress 6.8 Beta 3 is now ready for testing! This beta version of the WordPress software is under development. Please do not install, run, or test this version of WordPress…

Build a Code Snippet Web App with Next.js and FaunaDB

Exploring the Potential of the Metaverse: A New World Awaits
While programming, developers encounter problems requiring code reuse, leading to repetitive programming that can be time-wasting and reduces productivity. This gives rise to the need for reusable source code called…

What’s New in Node.js 20

What’s New in Node.js 20
Version 20 of Node.js was released on 18 April 2023. It addresses some issues and criticisms already “solved” by Deno and Bun, including a new permission model and a stable…