所以,让我说我有一个类似
的HTML结构<div class="outer">
<div class="inner">
<h1>Here's a headline</h1>
<p>Here's some text</p>
</div>
<div class="inner">
<p>Blah blah</p>
</div>
</div>
并且我希望在将loading
添加到outer
时,gif https://www.wpfaster.org/wp-content/uploads/2013/06/loading-gif.gif覆盖整个内容。有没有办法用伪元素做到这一点?添加background-image
的问题在于它在内部元素后面。
答案 0 :(得分:2)
这应该非常接近你想要的。可能需要调整背景颜色。
<强> CSS:强>
@-webkit-keyframes firstLayer {
from {
width: 0px;
margin-left: 0;
margin-top: 0;
height: 0px;
}
to {
width: 400px;
margin-left: -200px;
margin-top: -200px;
height: 400px;
}
}
答案 1 :(得分:2)
以下是一种方法:
.loading .inner { visibility: hidden; }
.loading {
background-image: url('https://www.wpfaster.org/wp-content/uploads/2013/06/loading-gif.gif');
background-size: contain;
background-repeat: no-repeat;
}
.loading .inner { visibility: hidden; }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="outer">
<div class="inner">
<h1>Here's a headline</h1>
<p>Here's some text</p>
</div>
<div class="inner">
<p>Blah blah</p>
</div>
</div>
<button onclick="$('.outer').toggleClass('loading')">Toggle</button>
&#13;