我正在尝试为此寻找替代方案:
“transition:background-image 1s whatever”
在 firefox 中,因为它只适用于 webkit 浏览器。
我已经尝试过不透明度替代方案,但这对我来说不是一个选择,因为我在背景容器上有内容,如果使用不透明度,这些内容将与背景一起消失。
谢谢。
最佳答案
你可以使用 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;
}
fiddle with real images
(悬停到过渡)
为了能够看到 div 内容,伪元素需要处于负 z-index 中:
fiddle with corrected z-index
看起来 IE 不会触发这个悬停
.test:hover:before {
opacity: 0;
}
但会触发这个
.test:hover {
}
.test:hover:before {
opacity: 0;
}
(看起来很傻)
关于html - Firefox 中背景图像的过渡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35574864/