If you don't (want to) know about the element height up front and 'grow' it to become the height it would normally occupy, you cannot use height: 100%
as this would make the element occupy 100% of its parent element height.
You can, however tell it may use N<unit>
in size (where N<unit>
is an arbitrary value like 10000px
or 1000em
, or whatever floats your boat).
@keyframes slideIn {
from {max- height: 0;}
to {max-height: 100%;}
}
But in order for this to work, you will also need some other properties set (outside the animation):
height: auto;
overflow: hidden;
@keyframes woot {
from { max-height: 0; }
to { max-height: 100em; }
}
.example1 {
max-height: 1em;
overflow: hidden;
transition: max-height 5s;
}
.example1:hover {
max-height: 100em;
}
.example2 {
overflow: hidden;
animation: woot 5s infinite alternate;
}
<div class=container>
<div class=example1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et volutpat lectus, ac hendrerit dui. Donec a vehicula nunc. Integer eleifend blandit libero vitae porttitor. In auctor odio a diam commodo dignissim. Donec vitae nisi fermentum, hendrerit augue at, sagittis erat. Mauris at consectetur sem. Duis ligula metus, fermentum vel vulputate vitae, lacinia nec turpis. Sed nec nibh porttitor, congue neque nec, laoreet purus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur facilisis mi imperdiet dignissim suscipit. Proin dictum varius velit eu eleifend. Vivamus imperdiet eleifend tortor, sit amet mollis leo auctor a. Sed condimentum nisi tortor, quis interdum sapien dignissim sed. Sed interdum, justo a ultrices sodales, risus nunc ultricies eros, et tempor nisl elit sed eros.
</div>
<br />
<div class=example2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et volutpat lectus, ac hendrerit dui. Donec a vehicula nunc. Integer eleifend blandit libero vitae porttitor. In auctor odio a diam commodo dignissim. Donec vitae nisi fermentum, hendrerit augue at, sagittis erat. Mauris at consectetur sem. Duis ligula metus, fermentum vel vulputate vitae, lacinia nec turpis. Sed nec nibh porttitor, congue neque nec, laoreet purus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur facilisis mi imperdiet dignissim suscipit. Proin dictum varius velit eu eleifend. Vivamus imperdiet eleifend tortor, sit amet mollis leo auctor a. Sed condimentum nisi tortor, quis interdum sapien dignissim sed. Sed interdum, justo a ultrices sodales, risus nunc ultricies eros, et tempor nisl elit sed eros.
</div>
</div>
There is one catch though, you will need to exaggerate the max-height value to the point where you are always certain the contents will fit, and it is the full value of said max-height that counts for the duration of the animation, not just the visible portion.