CSS圖片加黑色遮罩的步驟如下:
1、導(dǎo)入圖片:在HTML中,使用<img>
標簽導(dǎo)入圖片。
<img src="image.jpg" alt="圖片描述" />
2、編寫CSS樣式:在CSS中,使用position
屬性將圖片定位,并使用top
、left
、right
、bottom
屬性設(shè)置圖片的四個邊緣位置。
img { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
3、添加黑色遮罩:在CSS中,使用rgba
函數(shù)設(shè)置背景顏色為黑色,并設(shè)置透明度為0.5。
img { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); }
4、調(diào)整圖片大?。涸贑SS中,使用width
和height
屬性設(shè)置圖片的大小。
img { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); width: 100%; height: 100%; }
5、完成操作:確保HTML和CSS文件正確鏈接到頁面中,并檢查頁面顯示效果,如果操作正確,圖片上應(yīng)該會出現(xiàn)一個半透明的黑色遮罩。
版權(quán)聲明:除非特別標注,否則均為本站原創(chuàng)文章,轉(zhuǎn)載時請以鏈接形式注明文章出處。