css - 在背景图片上方添​​加透明色层

标签 css

我需要在背景图片上添加一个透明的彩色图层。我尝试用 rgba 这样做但没有结果。

我现在得到的是:

page-heading {
    background: rgba(36, 70, 105, 0.74) url("../images/samples/bg3.jpg") no-repeat fixed 50% 0px / cover;
    opacity: 0.9;
    position: relative;
    text-align: center;
    padding: 72px 0px;
}

我知道背景颜色是无法加载图像时的后备。如何以正确的方式在其上添加一层?

最佳答案

使用简单的 box-shadow 插图:

.page-heading {
    background: url(../images/samples/bg3.jpg) no-repeat fixed 50% 0px / cover;
    box-shadow: inset 0 0 0 100px rgba(36, 70, 105, 0.74);
}

JS fiddle :http://jsfiddle.net/ghorg12110/q0cLf2s7/

关于css - 在背景图片上方添​​加透明色层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33693070/

相关文章:

java - 为什么按钮在点击时调整大小

javascript - HTML 框架集问题

javascript - 从 <head> 中移除 &lt;style&gt; 标签

html - 实现页脚不会留在底部?

html - 模态高度和宽度调整

html - CSS:自动填充单元格表格和构建良好布局的方法?

css - 寻找一种更好的方法来删除 IE6 的空白

css - 在 Chrome 上转换字母间距

html - 李 :hover not encompassing entire menu button on screen resize

css - CSS 网格内 flexbox 的跨浏览器图像高度问题