隐藏 CSS 动画的内容溢出

时间:2021-06-16 14:30:21

标签: html css

我一直在尝试制作动画,并且几乎完成了。 我面临的唯一问题是水平和垂直滚动条没有隐藏。 我尝试将 overflow:hidden 属性添加到父 div,即 .box,但我仍然无法隐藏它们。

<!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>
      
      .box {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
      }
      .rotor1 {
        height: 100vw;
        background: rgb(152, 227, 250);
        animation: 9.2s keepRotating infinite ease-in-out;
        z-index: 3;
      }
      .rotor2 {
        height: 102vw;
        background: rgb(204, 238, 248);
        border-radius: 30%;
        animation: 9.05s keepRotating infinite ease-in-out;
        animation-timing-function: linear;
      }
      .rotor1,
      .rotor2 {
        width: 110vw;
        position: absolute;
        top: -78vw;
        border-radius: 30%;
        animation-timing-function: linear;
      }

      @keyframes keepRotating {
        from {
          transform: rotate(0deg);
        }
        to {
          transform: rotate(360deg);
        }
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="rotor1"></div>
      <div class="rotor2"></div>
    </div>
  </body>
</html>

有没有办法同时隐藏水平和垂直滚动条?

1 个答案:

答案 0 :(得分:1)

overflow: hidden; 上使用 body

<!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>
         body{
          overflow: hidden;
          }
        .box {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
      }
      .rotor1 {
        height: 100vw;
        background: rgb(152, 227, 250);
        animation: 9.2s keepRotating infinite ease-in-out;
        z-index: 3;
      }
      .rotor2 {
        height: 102vw;
        background: rgb(204, 238, 248);
        border-radius: 30%;
        animation: 9.05s keepRotating infinite ease-in-out;
        animation-timing-function: linear;
      }
      .rotor1,
      .rotor2 {
        width: 110vw;
        position: absolute;
        top: -78vw;
        border-radius: 30%;
        animation-timing-function: linear;
      }

      @keyframes keepRotating {
        from {
          transform: rotate(0deg);
        }
        to {
          transform: rotate(360deg);
        }
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="rotor1"></div>
      <div class="rotor2"></div>
    </div>
  </body>
</html>