使用css实现的毛玻璃效果

248 阅读1分钟
<!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>
    body {
      height: 2000px;
    }
    .box {
      width: 800px;
      height: 350px;
      background:url('https://images.pexels.com/photos/2050994/pexels-photo-2050994.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500') center center no-repeat;
      background-attachment: fixed;
      background-size: cover;
      position: relative;
      
    }
    .box .item {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
      z-index: 1;
      width: 80%;
      height: 55%;
      background-color: rgba(255, 255, 255, 0.5);
      color:white;
    }
    .box .item::before {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      filter: blur(10px);
      background: url('https://images.pexels.com/photos/2050994/pexels-photo-2050994.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500') center  center no-repeat;
      background-attachment: fixed;
      background-size: cover;
      z-index: -1;
    }

    .box .item p span:nth-child(2){
      display: inline-block;
      text-align: right;
    }
  </style>
</head>
<body>
  <div class="box">
    <div class="item">
      <p>明知会散落,仍不惧盛开</p>
      <p>
        <span>--</span>
        <span>忘记谁说的了</span>
      </p>
    </div>
  </div>
</body>
</html>