I need to animate the height of a div
that doesn't have a specified height. Using max-height
isn't an option due to multiple potential height amounts.
I attempted adding transition: height 0.2s ease
to the div
, but it didn't work as expected. How can I achieve height animation? CSS is preferred, but if necessary, I'm willing to use JavaScript.
.tabGroup {
background-color: brown;
color: yellowgreen;
transition: height 0.2s ease;
}
.tabGroup > div {
display: none;
}
.tab1:checked ~ .tab1,
.tab2:checked ~ .tab2,
.tab3:checked ~ .tab3 {
display: block;
}
<div class="tabGroup">
<input type="radio" name="tabGroup1" id="rad1" class="tab1" checked="checked" />
<label for="rad1">Tab 1</label>
<input type="radio" name="tabGroup1" id="rad2" class="tab2" />
<label for="rad2">Tab 2</label>
<input type="radio" name="tabGroup1" id="rad3" class="tab3" />
<label for="rad3">Tab 3</label>
<div class="tab1">
Content for Tab 1
</div>
<div class="tab2">
Content for Tab 2
</div>
<div class="tab3">
Content for Tab 3
</div>
</div>