![](https://img2020.cnblogs.com/blog/2216408/202103/2216408-20210327082149333-1811057056.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>土豆网遮罩--伪元素</title>
<style>
.box {
position: relative;
width: 448px;
height: 252px;
margin: 100px auto;
}
img {
width: 100%;
height: 100%;
}
a::after {
/* 伪元素必须有content */
content: '';
display: none;
position: absolute;
top: 0;
left: 0;
width: 448px;
height: 252px;
background-color: rgba(0, 0, 0, .3);
background: rgba(0, 0, 0, .3) url(arr.png) no-repeat center;
}
/*我是这样写的,他是对.box设置的伪元素所以相比于我的写法就没有a*/
.box:hover a::after {
display: block;
}
</style>
</head>
<body>
<div class="box">
<a href="#"><img src="tudou.jpg" alt=""></a>
</div>
</body>
</html>
.tudou::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;
}
/* ↓ 这没有空格的哟*/
.tudou:hover::before {
display: block;
}