土豆网遮罩效果——伪元素

<!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;
             448px;
            height: 252px;
            margin: 100px auto;
        }
        
        img {
             100%;
            height: 100%;
        }
        
        a::after {
           /* 伪元素必须有content */
            content: '';
            display: none;
            position: absolute;
            top: 0;
            left: 0;
             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;
             100%;
            height: 100%;
            background: rgba(0, 0, 0, .4) url(images/arr.png) no-repeat center;
        }

        /* ↓ 这没有空格的哟*/
        .tudou:hover::before {
            display: block;
        }
原文地址:https://www.cnblogs.com/icemiaomiao3/p/14584835.html