在很多網頁中我們會看到在一個圖片上面有一個半透明的色塊,上面寫有信息介紹,這個東西叫做蒙版,或者是遮罩。
那么這個蒙版是怎么實現的呢。。。
我們看下面這段代碼:
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>蒙版||遮罩</title> | |
<style> | |
.box1 { | |
width: 830px; | |
height: 470px; | |
border: 1px solid #000; | |
position: relative; | |
overflow: hidden; | |
} | |
.mengban{ | |
width: 100%; | |
height: 200px; | |
background-color: rgba(255,0,0,.5); | |
position: absolute; | |
bottom: 0; | |
transition: all linear 1s; | |
} | |
.box1:hover .mengban{ | |
bottom: -200px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="box1"> | |
<img src="img/watchingU.jpg" alt="pic"/> | |
<div class="mmengban>XX東西 XX錢...</div> | |
</div> | |
</body> | |
</html> |
上面的代碼就是寫蒙版的方式,這個只是下面的蒙版,如果要完成上下左右的蒙版都是一樣的,只是定位的方向和蒙版的寬高需要自己取調整。