DIV背景图像变化的CSS过渡

3 html css html5 css3

我试图应用过渡属性,以便在悬停时图像更改时产生效果,但似乎不起作用.请看看并帮助我.

.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);
}
Run Code Online (Sandbox Code Playgroud)

LGS*_*Son 8

转换background-image不能跨浏览器工作,因此请使用伪元素

运用 opacity

.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;
}
Run Code Online (Sandbox Code Playgroud)
<div class="ow-outer"></div>
Run Code Online (Sandbox Code Playgroud)

运用 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);
}
Run Code Online (Sandbox Code Playgroud)
<div class="ow-outer"></div>
Run Code Online (Sandbox Code Playgroud)