【问题标题】:background: url and filter:brightness背景:网址和过滤器:亮度
【发布时间】:2017-05-09 10:23:33
【问题描述】:

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

【问题讨论】:

  • 使用2个独立的divs,一个作为具有背景和大小的父级,另一个仅包含内容并拉伸以填充父级。
  • 我不明白,你能给我看看我的代码编辑吗?那么过滤器应该去哪里呢?

标签: html image css web


【解决方案1】:

当我谈到父母和孩子时,我实际上是错的。您必须将容器放在同一级别:

#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>

【讨论】:

  • 好的,谢谢,我不明白如何使用您之前的回答大声笑。它运行良好,但现在我的 text-vcenter donc 不再工作了。这是它的代码: .text-vcenter { display: table-cell;文本对齐:居中;垂直对齐:中间; }
  • 现在好了。把它放在行上也有效,但我更喜欢你的回答:)。感谢您的帮助:)。
猜你喜欢
  • 2014-08-23
  • 2018-06-21
  • 2013-01-09
  • 1970-01-01
  • 2013-07-22
  • 2014-11-08
  • 1970-01-01
  • 1970-01-01
  • 2011-05-16
相关资源
最近更新 更多