CSS3 3D transform-style

177 阅读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>
    .out {
      width: 500px;
      height: 500px;
      border: 1px solid #000;
      background-color: pink;
      margin: 100px auto;

      /* 用于调试,增大角度查看3D效果 */
      transform: rotateY(66deg);

      /* 可以让里面的子盒子保持3D效果,加给父盒子身上的话 */
      /* transform-style: flat; 让子盒子被扁平化, 默认值 */
      /* transform-style: preserve-3d; 让子盒子位于 3D 空间里面 */
      transform-style: preserve-3d;
    }
    .in {
      width: 300px;
      height: 300px;
      background-color: red;
      margin: 50px auto;
      transform: rotateX(132deg);
      border: 1px solid #000;
    }
  </style>
</head>
<body>
  <div class="out">
    <div class="in"></div>
  </div>
</body>
</html>
  • demo 效果