我想用 filter:brightness 使 div 的背景图像变暗。它运作良好,但显然它使整个 div 变暗,而不仅仅是图像。我怎样才能用 CSS 只使背景图像变暗?我想要一些白色的文字。
这是我的代码:
#about_header {
background: url(../img/background/spa_02.jpg) no-repeat center center fixed;
filter: brightness(20%);
-webkit-filter: brightness(20%);
-moz-filter: brightness(20%);
-o-filter: brightness(20%);
-ms-filter: brightness(20%);
height:400px;
display: table;
position: relative;
width: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#about_header h1{
color: white;
}
<section id="about_header">
<div class="container text-vcenter">
<div class="row">
<div class="col-sm-12">
<div>
<h1>Contact us</h1>
</div>
</div>
</div>
</div>
</section>
最佳答案
其实我说亲子的时候是错的。您必须将容器放在同一层下:
#about_header {
background: url("http://www.thestatedhome.com/media/catalog/category/13514044-brown-natural-linen-texture-for-the-background-Stock-Photo.jpg") no-repeat center center fixed;
filter: brightness(20%);
height: 400px;
position: relative;
width: 100%;
background-size: cover;
}
.container {
display: table;
position: absolute;
top: 0px;
height: 400px;
width: 100%;
}
.text-vcenter {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.container h1 {
color: white;
}
<section id="about_header"></section>
<div class="container">
<div class="text-vcenter">
<div class="row">
<div class="col-sm-12">
<div>
<h1>Contact us</h1>
</div>
</div>
</div>
</div>
</div>
关于html - 背景 : url and filter:brightness,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43859564/