CSS:怎么样给背景图加透明度 opacity ?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/henryhu712/article/details/81839860

CSS 中无法直接给背景图片加 opacity 属性,可以使用下面的方法绕过这个限制:

div {
  width: 200px;
  height: 200px;
  display: block;
  position: relative;
}

div::after {
  content: "";
  background: url(image.jpg);
  opacity: 0.5;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;   
}

猜你喜欢

转载自blog.csdn.net/henryhu712/article/details/81839860