伪元素法简易遮罩层

<!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>Document</title>
    <style>
      .container {
        position: relative;
        width: 200px;
        height: 266.66px;
      }

      .container img {
        width: 100%;
        height: 100%;
      }

      .container::before {
        content:"";
        display: none;

        position: absolute;
        width: 100%;
        height: 100%;
        background: #000;
        opacity: 0.5;
      }

      .container:hover::before {
        display: block;
      }

    
    </style>
  </head>
  <body>
    <div class="container">
      <!-- <div class="mask"></div> -->
      <img src="./1.jpg" alt="" />
    </div>
   
  </body>
</html>

你可能感兴趣的:(css3,css,前端)