Reputation: 423
I'm trying to create a container system that only shows/hides one menu at a time. It works for the most part, but I can't get the CSS transitions to work correctly. I've been looking at this for a couple hours and can't figure out why there are no transitions occurring at all.
The menu needs to drop down and scroll back up when a container is clicked. I just need a starting point on getting some kind of transition to occur when the user clicks a container.
CSS:
.singledrop {
display: none;
}
.singledroplabel h2 {
display: inline;
color: #4e4e50;
}
.singledrop+.content {
display: none;
height: 0px;
transition: height 0.2s ease-in-out;
-webkit-transition: height 0.2s ease-in-out;
-moz-transition: height 0.2s ease-in-out;
-ms-transition: height 0.2s ease-in-out;
}
.singledrop:checked+.content {
display: block;
height: auto;
}
HTML:
<div>
<label class="singledroplabel" for="drop1"><h2>Foo</h2></label>
<input class="singledrop" type="radio" name="menu" id="drop1" />
<div class="content">
foo<br/>
foo<br/>
foo<br/>
foo<br/>
foo<br/>
foo<br/>
foo<br/>
</div>
</div>
<div>
<label class="singledroplabel" for="drop2"><h2>Bar</h2></label>
<input class="singledrop" type="radio" name="menu" id="drop2" />
<div class="content">
bar<br/>
bar<br/>
bar<br/>
bar<br/>
bar<br/>
bar<br/>
bar<br/>
</div>
</div>
Upvotes: 0
Views: 294
Reputation: 73045
You can't animate to height:auto
. Try hardcoding a height, or setting max-height
to something huge.
http://jsfiddle.net/adambiggs/MAbD3/
is a good example of the max-height method.
Upvotes: 3