gpt4 book ai didi

html - DIV背景图像变化的CSS过渡

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:13 25 4
gpt4 key购买 nike

我尝试应用过渡属性在悬停时图像发生变化时产生效果,但它似乎不起作用。请看看并帮助我。

.ow-outer {
background-color: #fff;
width: 200px;
height: 200px;
border-radius: 50%;
border: 1px solid #fff;
text-align: center;
padding: 20px;
background-image: url(../images/team-canada-light.png);
background-size: 120px;
background-repeat: no-repeat;
background-position: center;
transition: all 0.3s ease-in-out;
}
.ow-outer:hover {
background-image: url(../images/team-canada.png);
}

最佳答案

background-image 上的过渡不能跨浏览器工作,因此请改用伪元素

使用不透明度

.ow-outer {
position: relative;
background-color: #fff;
width: 200px;
height: 200px;
border-radius: 50%;
border: 1px solid #fff;
text-align: center;
padding: 20px;
background: url(http://placehold.it/200) no-repeat center;
background-size: 120px;
}
.ow-outer::before {
content: '';
position: absolute;
left: 0; top: 0; right:0; bottom: 0;
background: url(http://placehold.it/200/f00) no-repeat center;
background-size: inherit;
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
.ow-outer:hover::before {
opacity: 1;
}
<div class="ow-outer"></div>

使用transform: scale

.ow-outer {
position: relative;
background-color: #fff;
width: 200px;
height: 200px;
border-radius: 50%;
border: 1px solid #fff;
text-align: center;
padding: 20px;
background: url(http://placehold.it/200) no-repeat center;
background-size: 120px;
}
.ow-outer::before {
content: '';
position: absolute;
left: 0; top: 0; right:0; bottom: 0;
background: url(http://placehold.it/200/f00) no-repeat center;
background-size: inherit;
transform: scale(0);
transition: transform 0.3s ease-in-out;
}
.ow-outer:hover::before {
transform: scale(1);
}
<div class="ow-outer"></div>

关于html - DIV背景图像变化的CSS过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42342419/

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