::before
元素的高度在悬停时平滑变化是必要的。transition
不起作用。有没有办法让事情在没有 JS 的情况下工作?
.card1 {
width: 239px;
height: 360px;
border-radius: 10px;
border: 2px solid rgb(42, 42, 42);
background-color: red;
position: relative;
cursor: pointer;
}
.card1::before {
content: "";
position: absolute;
width: 239px;
border-radius: 10px;
background-color: green;
}
.card1:hover::before {
height: 360px;
}
<div class="place">
<div class="card1"></div>
</div>
您需要设置初始高度
0px
。