Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
Best Way to Transition CSS Style Height from "0" to "auto"

I've seen this question and have not seen anyone provide this answer. The solution I created was perfect for my situation so I thought I'd share. Essentially, I had a page where a generated list was hidden at first by setting CSS height to "0" then expanded on click by transitioning height. However, transitions won't work with height = "auto". So I did some digging and realized that the CSS attribute "scrollHeight" will still calculate despite "height" or "max-height". So I set the "onclick" event to change the element height to the "scrollHeight".

document.getElementById('dropContent').style.height = document.getElementById('dropContent').scrollHeight + 'px';
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From the book CSS in Depth:

A value cannot transition from a length 0 to auto.

What you can do is set a height explicitly instead, the problem is that maybe you don't know what the height should be. That's only known once the contents are set and rendered in the browser, so you'll have to use JavaScript to determine the height. Unfortunately, there's no other workaround.

So you should keep using element.scrollHeight.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!