html - Firefox 中背景图像的过渡?

标签 html css firefox

我正在尝试为此寻找替代方案:

“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;
}

(看起来很傻)

fiddle for IE10

关于html - Firefox 中背景图像的过渡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35574864/

相关文章:

html - 在 Open Graph 标记中,没有位置 (href) 的 'og:locale:alternate' 有什么用?

html - 如何将 Canvas 重叠在 table 上

javascript - 有没有一种方法可以检测 Firefox 是否会在 IE 选项卡中打开特定的 URL?

c# - 捆绑后未将 Jquery UI css 添加到我的元素中

python selenium 因查找不存在的元素而挂起

firefox - 将 Firefox 插件安装到 Firefox OS Firefox 浏览器中

html - 如何从选择下拉列表中删除滚动条

html - 将带有背景图像的 div 更改为带过渡的彩色背景

hover - CSS 文本阴影属性不遵循 :visited pseudo-class 的层次结构

css - IonicPopup 在调用时更改背景颜色