在Firefox中转换背景图像?

Cai*_*uke 8 html css firefox css3

我想找到一个替代方案:

"transition:background-image 1s whatever"

Firefox中,因为它只适用于webkit浏览器.

我已经尝试了不透明度替代品,但这对我来说不是一个选项,因为我在背景容器上有内容,如果使用不透明度,它将与背景一起消失.

谢谢.

val*_*als 14

你可以使用2个伪元素来做到这一点

CSS

.test
{
    width: 400px;
    height: 150px;
    position: relative;
    border: 1px solid green;
}

.test:before, .test:after {
    content: "";
    position: absolute;
    top: 0px;
    right: 0px;
    bottom: 0px;
    left: 0px;
    opacity: 1;
}
.test:before {
    background-color: red;
    z-index: 1;
    transition: opacity 1s;
}

.test:after {
    background-color: green;
}

.test:hover:before {
    opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)

摆弄真实的图像

(悬停过渡)

为了能够看到div内容,伪元素需要在负z-index中:

纠正z-index

看起来IE不会触发这个悬停

.test:hover:before {
    opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)

但会触发这一个

.test:hover {
}
.test:hover:before {
    opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)

(如同SILLY似乎)

IE10的小提琴