html - 背景 : url and filter:brightness

标签 html image css web

我想用 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/

相关文章:

javascript - 在 Canvas 中围绕其中心旋转图像

python - 使用 Numpy 在 Python 中处理图像

.net - 如何从 .NET 中的图标文件中提取特定图像?

javascript - jQuery 弹出窗口点击任意位置关闭弹出窗口添加关闭功能

php - 由于 config.js 文件,上传到 Web 服务器后布局和功能被破坏

javascript - 为什么使用忽略垃圾工件的方法替换段落内容不起作用?

javascript - Rails 根据用户输入动态更新 View

html - 如何仅使用 css/html 使文本滑动

html - Div重叠

html - 不同级别的内联 block div