<分区>
<分区>
我正在尝试为我的整页背景图像设置不透明度,但是当我添加不透明度代码时,我的整个 html 的不透明度为 0.4,图像除外。
html {
background: url(../img/bg2.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
我试着像这样添加不透明度:
html {
background: url(../img/bg2.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
opacity: 0.4;
}
但正如我所说,我的整个 html 变成了 0.4
我尝试在 background: url(../img/bg2.jpg) no-repeat center center fixed 0.4;
之后添加 0.4,但我的图像随后就变成了空白。
如何将 0.4 仅添加到我的背景图像?
最佳答案
尝试使用 ::after
伪类:
html::after {
content: "";
background: url(../img/bg2.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
opacity: 0.4;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
关于html - 提供背景图像和不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33889762/