gpt4 book ai didi

css - 悬停过渡CSS

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:28 25 4
gpt4 key购买 nike

这个问题可能很明显,但我是 CSS 新手。

我正在制作一个形状的动画,因此当您悬停它时,它会拉伸(stretch)。我已经通过一个很好的轻松过渡完成了悬停,但是当你离开鼠标时,过渡不起作用。有没有办法让它在悬停时刻也发生?

.shape1{
position: absolute;
background:red
top:512px;
width:180px;
height:140px;
}

.shape1:hover {
height: 160px;
top:492px;
transition: 0.2s ease;
}

最佳答案

你的答案

您已在元素的悬停状态上添加了 transition 属性。因此,当您离开元素的 cursor 时,不会应用 transition

.shape1{
position: absolute;
background: red;
top: 512px;
width: 180px;
height: 140px;
transition: .2s ease; /* move this here from :hover */
}

更多信息

除此之外,您还可以将特定属性添加到transition。例如,如果您只想让高度具有动画效果,您可以这样:

.shape1 {
transition: height .2s ease;
/* this inly affects height, nothing else */
}

您甚至可以为每个属性定义不同的转换时间:

.shape1 {
transition: height .2s ease, background-color .5s linear;
/* stacking transitions is easy */
}

关于css - 悬停过渡CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45684693/

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