CSS 过渡不起作用

标签 css

我正在尝试创建一个一次只显示/隐藏一个菜单的容器系统。它在大多数情况下都有效,但我无法让 CSS 转换正常工作。我已经看了几个小时了,但无法弄清楚为什么根本没有发生任何转换。

单击容器时,菜单需要下拉并向上滚动。我只需要一个起点,让用户单击容器时发生某种转换。

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>

最佳答案

您不能为 height:auto 设置动画。尝试对高度进行硬编码,或将 max-height 设置为巨大的值。

http://jsfiddle.net/adambiggs/MAbD3/

是最大高度方法的一个很好的例子。

关于CSS 过渡不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14469134/

相关文章:

php - 在 Bootstrap 模式中提供 php 图像搜索结果

html - 如何仅使用 CSS 在 HTML 按钮上添加 FontAwesome 图标?

html - IE删除

html - 我可以每行放置三个盒子,等距放置并粘在左右两侧的容器上吗?

html - 输入元素大于指定

CSS 导航栏 - 基于导航栏内的元素居中

javascript - <video> 标签让我的按钮不可见

javascript - 如何从一个内置于 javascript/html 的选项卡开始,而不是它是空白的并且必须点击一个

jquery - 隐藏水平滚动条是个坏主意?

jQuery 根据内容的高度放置按钮