要实现的效果:
开始显示:
当鼠标经过时,显示遮罩层:
下面是用伪元素选择器实现遮罩层:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
position: relative;
width: 390px;
height: 210px;
background-color: pink;
margin: 30px auto;
}
.container img {
width: 100%;
height: 100%;
}
.container::before {
content: '';
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .4) url(images/arr.png) no-repeat center;
}
.container:hover::before {
display: block;
}
</style>
</head>
<body>
<div class="container">
<img src="images/longxia.png" alt="">
</div>
</body>
</html>