在相对定位的文本后面定位不透明的伪内容
Positioning opaque pseudo content behind relatively positioned text
我试图在一些文本后面放置一个不透明的黑色背景,但遇到了麻烦,因为文本总是在不透明的颜色后面。我不能使用 z-index,因为文本是相对定位的,有谁知道我怎样才能让文本出现在不透明背景之上?
JS fiddle
HTML
<section class="primary" style="background-image: url('http://lorempixel.com/output/fashion-q-c-640-480-9.jpg');" data-bgimg="http://lorempixel.com/output/fashion-q-c-640-480-9.jpg">
<div class="item">
<article>
<div class="entry">
<p>A whole bunch of text that goes on top of everything but is relatively positioned</p>
</div>
<div class="clear"> </div>
</article>
</div> <!-- End div.item -->
<p class="scroll-down">Scroll down</p>
</section>
CSS
section {
position:relative; text-align: center;
background-repeat: no-repeat; background-size: cover;
min-height:100%; color:#fff;
}
.item:after {
content: ''; position:absolute; width:100%; height:100%; top:0; left:0;
background-color:#000; opacity:0.3;
}
我想我不明白你的问题,但它仍然值得一试。
http://jsfiddle.net/DIRTY_SMITH/abtuj3xj/1/
section {
position:relative; text-align: center;
background-repeat: no-repeat; background-size: cover;
min-height:100%; color:#fff;z-index: -9999;
}
.item:after {
content: ''; position:absolute; width:100%; height:100%; top:0; left:0;
background-color:#000; opacity:0.3; z-index: -9999;
}
我试图在一些文本后面放置一个不透明的黑色背景,但遇到了麻烦,因为文本总是在不透明的颜色后面。我不能使用 z-index,因为文本是相对定位的,有谁知道我怎样才能让文本出现在不透明背景之上?
JS fiddle
HTML
<section class="primary" style="background-image: url('http://lorempixel.com/output/fashion-q-c-640-480-9.jpg');" data-bgimg="http://lorempixel.com/output/fashion-q-c-640-480-9.jpg">
<div class="item">
<article>
<div class="entry">
<p>A whole bunch of text that goes on top of everything but is relatively positioned</p>
</div>
<div class="clear"> </div>
</article>
</div> <!-- End div.item -->
<p class="scroll-down">Scroll down</p>
</section>
CSS
section {
position:relative; text-align: center;
background-repeat: no-repeat; background-size: cover;
min-height:100%; color:#fff;
}
.item:after {
content: ''; position:absolute; width:100%; height:100%; top:0; left:0;
background-color:#000; opacity:0.3;
}
我想我不明白你的问题,但它仍然值得一试。
http://jsfiddle.net/DIRTY_SMITH/abtuj3xj/1/
section {
position:relative; text-align: center;
background-repeat: no-repeat; background-size: cover;
min-height:100%; color:#fff;z-index: -9999;
}
.item:after {
content: ''; position:absolute; width:100%; height:100%; top:0; left:0;
background-color:#000; opacity:0.3; z-index: -9999;
}