【发布时间】:2021-10-18 15:23:52
【问题描述】:
我有以下代码,其中当圆圈悬停时,它的大小会增加(放大),并且它会在 2 秒内顺利完成。同时,圆圈也将其背景颜色从黑色变为白色,但这很突然,请参阅:
div {
width: 100px;
height: 100px;
color: white;
background-color: black;
border: 2px solid white;
position: relative;
right: -250px;
bottom: -150px;
border-radius: 50%;
transition: width 2s, height 2s;
}
div:hover {
background-color: white;
width: 200px;
height: 200px;
}
<body style="background-color: purple">
<div></div>
</body>
但是,我希望从黑色到白色的过渡平滑。我想出了一个解决方案,就是在CSS中添加transition: all 2s ease;到div:
div {
width: 100px;
height: 100px;
color: white;
background-color: black;
border: 2px solid white;
position: relative;
right: -250px;
bottom: -150px;
border-radius: 50%;
transition: width 2s, height 2s;
transition: all 2s ease;
}
div:hover {
background-color: white;
width: 200px;
height: 200px;
}
<body style="background-color: purple">
<div></div>
</body>
但在 CSS 的 DIV 部分中有两个 transition 属性,我对此表示怀疑。有没有其他方法可以绕过它?
【问题讨论】:
标签: html css hover transition