简体   繁体   中英

CSS3 - Variable height accordion using transitions

I've coded two small jQuery based scripts, one of accordions, and one of tabs, but then i realized that they were the same : get the clicked tab's index among other tabs, and only show the content that has the same index among contents.

But there's one annoying difference between the two : the animation. While tabs are only using the display property, accordions need to animate the height of content blocks.

Problem is that it is not possible to animate from height: 0; to height: auto;. There is a way to do it differently, using max-height, as described in [this] other SO question, but i don't really like this solution because it's hard-coded and doesn't always work.

Is there a way to animate a block's height from 0 to it's content height without using max-height or javascript ?

Thanks for your help !

No. CSS transitions can only go from a value (or no value indicating a zero value) to another value. They cannot go from a value (or zero value) to a non-zero undetermined value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM