在CSS中,您可以使用position
屬性來設(shè)置遮罩層的固定位置,以下是一些示例代碼,展示如何將遮罩層固定在頁面的不同位置:
1. 固定在頁面頂部
.mask { position: fixed; top: 0; left: 0; width: 100%; height: 50px; background-color: rgba(0, 0, 0, 0.5); }
2. 固定在頁面底部
.mask { position: fixed; bottom: 0; left: 0; width: 100%; height: 50px; background-color: rgba(0, 0, 0, 0.5); }
3. 固定在頁面左側(cè)
.mask { position: fixed; top: 0; left: 0; width: 50px; height: 100%; background-color: rgba(0, 0, 0, 0.5); }
4. 固定在頁面右側(cè)
.mask { position: fixed; top: 0; right: 0; width: 50px; height: 100%; background-color: rgba(0, 0, 0, 0.5); }
5. 固定在頁面中心(***定位)
.mask { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100px; height: 100px; background-color: rgba(0, 0, 0, 0.5); }
6. 固定在特定位置(相對定位)
.mask { position: relative; top: 20px; left: 30px; width: 150px; height: 200px; background-color: rgba(0, 0, 0, 0.5); }
版權(quán)聲明:除非特別標(biāo)注,否則均為本站原創(chuàng)文章,轉(zhuǎn)載時請以鏈接形式注明文章出處。