css通过伪元素实现鼠标经过出现灰色蒙层

694 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>伪元素</title>
    <style>
        .wrapper{
            width: 260px;
            height: 160px;
            margin-bottom: 20px;
            position: relative;
        }
        img{
            width: 100%;
            height: 100%;
        }
        .wrapper::before{
            /* 需要显示的内容为空 */
            content: '';
            /* color: #fff; */
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, .3) url(success.png) no-repeat center;
            background-size: 30px 30px;
        }
        .wrapper:hover::before{
            display: block;
        }
    </style>
</head>
<body>
    <div class="wrapper">
       <img src="zjl.jpg" alt="">
    </div>
    <div class="wrapper">
        <img src="zjl.jpg" alt="">
    </div>
    <div class="wrapper">
        <img src="zjl.jpg" alt="">
     </div>
     <div class="wrapper">
         <img src="zjl.jpg" alt="">
     </div>
</body>
</html>

在这里插入图片描述