gpt4 book ai didi

html - 从固定高度到悬停时自动

转载 作者:太空宇宙 更新时间:2023-11-04 09:24:19 24 4
gpt4 key购买 nike

我想在悬停时显示一些文本,从固定高度到 child 的全高,但似乎无法实现。

这是片段:

.c1 {
width: 50%;
max-height: 100px;
background: red;
overflow:hidden;
transition: max-height 4s ease-in;
}

.c1:hover {
max-height: auto;
}
<div class="c1">
<div style="width:auto;height;300px">
text text text text text text
texttext text texttext text texttext text texttext text texttext
text texttext text texttext text texttext text texttext text
texttext text texttext text texttext text texttext text texttext
text texttext text texttext text texttext text texttext text
texttext text texttext text texttext text texttext text texttext
text texttext text texttext text texttext text texttext text
texttext text texttext text text
</div>
</div>

我希望红色区域慢慢向下扩展以显示其余文本。有什么想法吗?

最佳答案

您的问题是最大高度没有值 auto

你要找的是 max-height: none,但是它不是可动画的。要为这个过渡动画,你必须给它一个特定的高度。

如果你将你的 Css 悬停类更改为此

.c1:hover {
/* No Animation*/
max-height: none;
}

.c1:hover {
/* With Animation*/
max-height: 300px;
}

来自 CSS Tricks 的 Chris Coyier 正在谈论它。 https://css-tricks.com/css-animate-fromto-auto/

现在,您真的不应该使用内联 CSS 和链接 CSS。并且有一些冗余代码,例如您根本不需要添加的内联 css。

关于html - 从固定高度到悬停时自动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41234895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com