I gave height of 0px
to an element as shown below
#sample{
height: 0px;
overflow: hidden;
transition-duration: 1.2s;
}
<div id="sample">
<h1>Hello World main headinh</h1>
<h2>Hello World sub heading</h2>
<p>Hello world paragraph</p>
</div>
If I'd not specified height so it will take height of content (say 50px). Now initially I dont know the height of #sample
. I want to set its height to its original calculated height (i.e. 50px), I can do it by giving height 100%
.
document.getElementById("sample").style.height = "100%";
But transition-duration
property is not working in that case, so when I change percent into pixel so transition-duration
property worked well.
document.getElementById("sample").style.height = "50px";
But problem here is the content inside the div
is dyanamic, so its height is changing too.
So how can I give height to the #sample
in pixel as much as that content need.
Solution should only have Javascript
not any other framework like JQuery
.