gpt4 book ai didi

html - 背景过度伪 z-index

转载 作者:行者123 更新时间:2023-11-28 00:58:34 24 4
gpt4 key购买 nike

你好 我已经尝试使用伪元素创建背景色叠加层,但问题是像 h2 这样的内部内容(在本例中)将位于背景叠加层之下,我知道我可以给出 h2 相对位置和 z-index 但我被问到是否有办法让我写更少的代码:

.breadCrumbs{
width:100%;
padding:20px 0;
position:relative;
background-image:url('http://store6.up-00.com/2017-04/149189733741781.jpg');
background-size:cover;
background-attachment:fixed;
}
.breadCrumbs:after{
content:'';
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
background-color:rgba(51, 51, 51, 0.60);
}
.breadCrumbs h2{
margin-bottom:30px;
color:#ffffff;
font-size:40px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<section class="breadCrumbs text-center">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2>Contact</h2>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="pages.html">Pages</a></li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</section>

最佳答案

使用 before 而不是 after

.breadCrumbs{
width:100%;
padding:20px 0;
position:relative;
background-image:url('http://store6.up-00.com/2017-04/149189733741781.jpg');
background-size:cover;
background-attachment:fixed;
}
.breadCrumbs:before{
content:'';
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
background-color:rgba(51, 51, 51, 0.60);

}
.breadCrumbs h2{
margin-bottom:30px;
color:#ffffff;
font-size:40px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<section class="breadCrumbs text-center">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2>Contact</h2>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="pages.html">Pages</a></li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</section>

关于html - 背景过度伪 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43339971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com