html - 为什么具有 ::before 和 ::after 的多个 div 在 chrome 中具有单个背景图像,而 Firefox 显示多个背景图像?
问题描述
我的代码在 chrome 中运行良好,但在 Firefox 中表现不同。在这里,我使用带有伪元素::after和::before的多个 div ,它们在 chrome 网络浏览器中运行时将所有 div 元素的背景图像作为单个(许多 div ≡ 一个背景图像)。
但在 Firefox 中,单独的 div 元素获取每个背景图像(许多 div ≡ 许多背景图像)。那么如何解决火狐浏览器的这个问题呢?
我使用的示例 Html 和 css 代码是:
$('.container div').mouseover(function(){
$(this).addClass('flip')
})
body{
margin: 0;
padding: 0;
}
.container{
width: 100%;
height: 100vh;
background-size: cover;
overflow: hidden;
background: green;
font-size: 0;
}
.container div{
position: relative;
display: block;
float: left;
width: 20%;
height: 20vh;
box-sizing: border-box;
}
.container div:hover{
z-index: 10000;
}
.container div::before{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://wallpaperplay.com/walls/full/2/e/6/205615.jpg);
background-attachment: fixed;
background-size: cover;
transform-style: preserve-3d;
transform-origin: top;
transform: perspective(1000px) rotateX(0deg) translateY(0);
transition: 0.5s linear;
padding: 1px;
}
.container div.flip::before{
transform: perspective(1000px) rotateX(90deg) translateY(-50%);
}
.container div::after{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://wallpaperhd.wiki/wp-content/uploads/laptop-wallpapers-s26hfq.jpg);
background-attachment: fixed;
background-size: cover;
transform-style: preserve-3d;
transform-origin: bottom;
transform: perspective(1000px) rotateX(-90deg) translateY(50%);
transition: 0.5s linear;
padding: 1px;
}
.container div.flip::after{
transform: perspective(1000px) rotateX(0deg) translateY(0);
}
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
解决方案
推荐阅读
- sql - 基于日期的 Oracle SQL 最近行
- kdb - 使用over副词对桌子进行操作
- javascript - 打字稿尝试更新我的对象中的布尔属性收到“TypeError:无法分配给只读属性”
- ios - 点击时如何调整 UIImageView 的大小?
- asp.net-mvc - asp.net mvc中的Excel导出和导入
- microsoft-teams - Microsoft Teams 连接器配置保存失败
- angular - ngdart 生成组件不生成 css 文件?
- node.js - 为什么闪存错误并非一直有效?
- mongodb - 如何将数据库移动到mongodb中的另一个分片
- python-3.x - Python - 浏览器在脚本完成之前关闭请求