css 渐变背景色过度效果

73 阅读1分钟

效果如下

过度.gif

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <style>
    .container {
      width: 384px;
      height: 215px;
      transition: opacity 1s ease-in-out;
      position: relative;
    }

    .container::before,
    .container::after {
      border-radius: 16px;
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0;
      transition: opacity 1s ease-in-out;
      backdrop-filter: blur(4px);
    }

    .container::before {
      background-image: linear-gradient(151deg, #D7E5FD 11.25%, #F7FDFE 85.08%);
      opacity: 1;
    }

    .container::after {
      background-image: linear-gradient(116deg, #3665FA 4.14%, #8B6DFF 84.34%);
    }

    .container:hover::before {
      opacity: 0;
    }

    .container:hover::after {
      opacity: 1;
    }
  </style>
</head>

<body>
  <div class="container"></div>
</body>

</html>

过度1.gif

  <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <style>
    .container {
      border-radius: 16px;
      width: 384px;
      height: 215px;
      position: relative;
      display: inline-block;
      color: white;
      background-image: linear-gradient(151deg, #D7E5FD 11.25%, #F7FDFE 85.08%);
      overflow: hidden;
    }

    .container::after {
      content: "";
      position: absolute;
      bottom: 0;
      right: 0;
      width: 0;
      height: 0;
      background-image: linear-gradient(116deg, #3665FA 4.14%, #8B6DFF 84.34%);
      transition: width 0.5s, height 0.5s;
    }

    .container:hover::after {
      width: 100%;
      height: 100%;
    }
  </style>
</head>

<body>
  <div class="container"></div>
</body>

</html>