将颜色和背景图像叠加在同一个 div
Overlay color and background image on the same div
这可能吗?要将背景颜色叠加 和 背景图像全部放在一个 div 上?如:
div {
color: white;
background-color: hsla(15, 92%, 13%, 0.79);
height: 500px;
background-image: url('http://via.placeholder.com/500x500');
}
<div>
<p>Content goes here</p>
</div>
谢谢!
你可以像这样使用伪元素:
div {
position: relative;
color: white;
background-image: url('http://via.placeholder.com/500x500');
height: 500px;
}
div:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
background: hsla(15, 92%, 13%, 0.79);
z-index: 0;
}
p {
position: relative;
z-index: 2;
}
<div>
<p>Content goes here</p>
</div>
div {
color: white;
background: url('http://via.placeholder.com/500x500');
background-color: hsla(15, 92%, 13%, 0.79);
background-blend-mode: overlay;
height: 500px;
}
<div>
<p>Content goes here</p>
</div>
这是你需要的吗?
这可能吗?要将背景颜色叠加 和 背景图像全部放在一个 div 上?如:
div {
color: white;
background-color: hsla(15, 92%, 13%, 0.79);
height: 500px;
background-image: url('http://via.placeholder.com/500x500');
}
<div>
<p>Content goes here</p>
</div>
谢谢!
你可以像这样使用伪元素:
div {
position: relative;
color: white;
background-image: url('http://via.placeholder.com/500x500');
height: 500px;
}
div:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
background: hsla(15, 92%, 13%, 0.79);
z-index: 0;
}
p {
position: relative;
z-index: 2;
}
<div>
<p>Content goes here</p>
</div>
div {
color: white;
background: url('http://via.placeholder.com/500x500');
background-color: hsla(15, 92%, 13%, 0.79);
background-blend-mode: overlay;
height: 500px;
}
<div>
<p>Content goes here</p>
</div>
这是你需要的吗?