CSS过渡最大高调回到0不起作用



我有一个简单的div,其高度和最大高度设置为10px。当我悬停在它上时,它应该扩展到DIV的全高度,当我离开时,它应该收缩回10px。

但是,当我解开时,下面的代码不会平稳地回到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;
}

https://jsfiddle.net/3hfxg6he/2/

从您的代码中删除height:10px;。它将在高度优先级的高度上使高度为10px,并使溢出陷入困境。这就是为什么动画不起作用的原因。有关max-height属性的更多详细信息,请访问此链接

.animate{
  font-size:20px;
  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;
}
<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>

相关内容

  • 没有找到相关文章

最新更新