My goal is to smoothly transition from height: 0;
to height: auto;
and reveal the content inside a <div></div>
. One effective method I've come across involves using the max-height
property. Here's an example of how it can be implemented:
#menu #list {
max-height: 0;
transition: max-height 0.15s ease-out;
overflow: hidden;
background: #d5d5d5;
}
#menu:hover #list {
max-height: 500px;
transition: max-height 0.25s ease-in;
}
<div id="menu">
<a>hover over me</a>
<ul id="list">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
While this method works well, there is a challenge when dealing with dynamic data retrieved from a database. The number of items within the list can vary greatly, making setting a fixed max-height
impractical. Adjusting max-height
based on the number of items through JavaScript would be complex and not ideal for responsive design.
I am seeking a solution that can accommodate both large and small amounts of items in a <ul>
while maintaining smooth transitions. Ideally, a purely CSS-based solution would be perfect, but I am open to incorporating JavaScript if necessary.