gpt4 book ai didi

html - 如何在悬停时展开 div 及其内容?

转载 作者:太空狗 更新时间:2023-10-29 13:34:30 24 4
gpt4 key购买 nike

我正在尝试创建一个在悬停时展开的 div,但无法弄清楚如何使内容随 div 一起展开。我尝试了一些溢出选项,但它们没有用。

.grow {
padding: 5px 5px 5px 5px;
border-radius:10px;
height: 50px;
width: 22%;
margin: 5px 1% 5px 1%;
float: left;
position: relative;
transition:height 0.5s;
-webkit-transition:height 0.5s;
text-align: center;

}
.grow:hover {
height: 115px; /* This is the height on hover */
}
<div class="grow" style="background-color: #2a75a9;">
<h2>Title</h2> <br>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature
</div>

这是 JSFiddle

最佳答案

添加overflow: hidden到父(.grow)容器隐藏描述。这将在悬停时显示描述。

此外,不要使用 <br />标记,将文本包装在 <p> 中标签。

.grow {
padding: 5px 5px 5px 5px;
border-radius: 10px;
height: 49px;
width: 22%;
margin: 5px 1% 5px 1%;
float: left;
position: relative;
transition: height 0.5s;
-webkit-transition: height 0.5s;
text-align: center;
overflow: hidden;
}
.grow:hover {
height: 145px;
}
<div class="grow" style="background-color: #2a75a9;">
<h2>Title</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature</p>
</div>

关于html - 如何在悬停时展开 div 及其内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27441404/

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