html - CSS 调整图像背景而不是内容的亮度

标签 html css filter

该部分有一个背景图像,顶部有内容。
我只想降低该部分中背景图像的亮度,而不是降低内容的亮度。

我已经尝试了下面的方法,但是,亮度仍然适用于所有人,而不仅仅是图像。

<!-- Section -->
<div id="section1">
    <div id="content">



    <h1 class="heading">headline text</h1>
    <h4 class="subHeading"> Sub-headline text</h4>

    <!-- Call to action button -->
    <br><br>
    <button> Join our wait list </button>

</div>
#section1 {
background: url('../images/headerimage1.jpg') center center no-repeat;
background-size: cover;
-webkit-filter: brightness(0.5);
filter: brightness(0.5);
    padding-top: 100px;
    padding-bottom: 100px;
    padding-left: 10%;
    padding-right: 10%;
    color: white;
    text-align: center;
}

#content {
  -webkit-filter: brightness(1);
filter: brightness(1);
}

最佳答案

您可以添加一个新的透明黑色元素,该元素仅覆盖背景,而 div 的内容位于其前面。

<div id="section1">
    <div id="content">
    </div>
</div>

CSS:
#section1 {
    background: url('../images/headerimage1.jpg') center center no-repeat;
    background-size: cover;
    position: relative;
}

#content {
    position: absolute;
}

#section1::before {
    content: '';
    display: block;
    position: absolute;
    background-color: #000;
    opacity: 0.5;
    width: 100%;
    height: 100%;
}

关于html - CSS 调整图像背景而不是内容的亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36066085/

相关文章:

javascript - 实现流畅的 JS tile 界面

html - AngularJS 错误,值未替换 {{clientCount}}

css - 如何阻止页面上的内容移动?

html - Angular JS 指令 - CSS 文件相对于 HTML 的位置

javascript - 如何通过在其他元素上调用上下文来在输入类型 "click"上调用 "file"?

javascript - Google Chrome 和 Firefox 的 jquery ajax html 问题

javascript - jQuery- 隐藏表 -> 重新加载页面后,我的表显示了几秒钟

javascript - 使用 Javascript onkeyup() 更改 IE8 中的不透明度(再次)

javascript - 如何根据多属性和多属性值显示/隐藏元素?

r - 如何比较两列的值然后根据结果创建第三个/新数据框