css如何使用opacity屬性給背景圖片加透明度(代碼)

來源:互聯網
上載者:User

本篇文章給大家帶來的內容是關於css如何使用opacity屬性給背景圖片加透明度(代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

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;   }
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.