firefox中背景图像的过渡? [英] transition for background-image in firefox?
问题描述
我正在为此寻找替代方案:
I am trying to find an alternative for this:
"transition:background-image 1s 随便"
在 firefox 中,因为它仅适用于 webkit 浏览器.
in firefox since it only works on webkit browsers.
我已经尝试了不透明度替代方案,但那不是我的选择,因为我在背景容器上有内容,如果使用不透明度,这些内容将与背景一起消失.
I already tried the opacity alternative but thats not an option for me since i have content on the background container which will disappear along with the background if using opacity.
谢谢.
推荐答案
你可以使用 2 个伪元素来做到这一点
You can do that using 2 pseudo elements
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
(hover to transition)
为了能够看到 div 内容,伪元素需要在负 z-index 中:
To be able to see the div content, the pseudo elements need to be in negative z-index:
看起来 IE 不会触发此悬停
looks like IE won't trigger this hover
.test:hover:before {
opacity: 0;
}
但是会触发这个
.test:hover {
}
.test:hover:before {
opacity: 0;
}
(看起来很傻)
这篇关于firefox中背景图像的过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!