CSS3 backface-visibility 让盒子的背面不可见

158 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      background-color: deepskyblue;
    }
    .box {
      width: 300px;
      height: 300px;
      margin: 100px auto;
      position: relative;
    }
    .box::after, .box::before {
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: pink;
      background: url(DemoMaterial/3D/bg.png) no-repeat;
      transition: all 1s;

      /* backface-visibility 让盒子的背面不可见 */
      backface-visibility: hidden;
    }
    .box::after {
      /* left: 350px; */
      background-position: right;
    }
    .box::before {
      transform: rotateY(-180deg);
    }
    .box:hover::before {
      transform: rotateY(0deg);
    }
    .box:hover::after {
      transform: rotateY(180deg);
    }
  </style>
</head>
<body>
  <div class="box"></div>
</body>
</html>

  • 拆开效果


  • 合并效果


  • 素材