且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何仅更改背景图像的不透明度?

更新时间:2021-09-05 23:05:30

您也可以通过伪元素来执行此操作.像这样:

You could also do this by a pseudo element. Something like this:

section {
   position: relative;
   padding: 15px;
   width: 100%;
   height: 700px;
}

section::before {
  content: "";
  position: absolute;
  top: 0; 
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  opacity: .5; 
  background-image: url(../IMG/Photo_NR1.jpg);
}

因此,您不需要图像标签,而是将设计与内容分开.

So you do not need an image tag and you separating the design from content.