我有一个简单的div,其高度和最大高度都设置为10像素。当我悬停在它上面时,它应该扩展到整个div的高度,当我离开时,它应该缩回到10像素。
但是当我取消悬停时,以下代码无法平稳地过渡回0。
HTML
但是当我取消悬停时,以下代码无法平稳地过渡回0。
HTML
<div class="animate">
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</div>
CSS
.animate{
font-size:20px;
height : 10px;
max-height:10px;
width: 100px;
overflow:hidden;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.animate:hover{
height:auto;
max-height:1000px;
}
max-height
应该覆盖height
,所以不确定您所说的高度具有“高优先级”的含义。https://developer.mozilla.org/zh-CN/docs/Web/CSS/max-height - Michael Benjaminmax-height
值时发生。但是这里他只给了最小值10px
,低于:hover
的max-height
属性。这就是为什么我们必须将其删除的原因。 - jafarbtech