Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webkit-transition height for a div with a dynamic changing height based on content?

Tags:

please see the following jsFiddle

http://jsfiddle.net/SgyEW/10/

You can click the various buttons which shows different length content which causes the box to grow/shrink.

I want the height change to be animated so it is not so jumpy, I tried this by adding:

-webkit-transition: all 1s linear; 

But that has no effect in this use case. Any ideas in terms of a solution that doesn't require JavaScript?

Thanks

like image 801
TheExit Avatar asked Jul 05 '11 20:07

TheExit


People also ask

How can we get dynamic height of div?

We use css property height: calc( 100% - div_height ); Here, Calc is a function. It uses mathematical expression by this property we can set the height content div area dynamically.

How do you animate dynamic height in CSS?

For animate the "height" of element with CSS Transitions you need use "max-height". If use the "height: auto", the effect not works. Is necessary some value for the CSS create a CSS animate, and you can use "max-height" with a great value for emulate this effect.

Does transition work on height?

We can't transition height , but we can transition max-height , since it has an explicit value. At any given moment, the actual height of the element will be the minimum of the height and the max-height .


1 Answers

I'm afraid there is no way of animating height with CSS3 transitions without some Javascript assistance, check out:

How can I transition height: 0; to height: auto; using CSS?

Can you use CSS3 to transition from height:0 to the variable height of content?

Additionally, your code goes from display: none to display: block, which wouldn't have an effect on height in any case. Instead of display none use height: 0 with overflow: hidden;

like image 148
methodofaction Avatar answered Sep 23 '22 13:09

methodofaction