欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CSS 3D动态立体图形

程序员文章站 2022-03-25 16:42:38
...

CSS 3D动态 立方体


1. HTML

<body>
  <div class="box">
    <div class="test"></div>
    <div class="test"></div>
    <div class="test"></div>
    <div class="test"></div>
    <div class="test"></div>
    <div class="test"></div>
  </div>
</body>

2. CSS

  <style type="text/css">
    .box {
      width: 500px;
      height: 500px;
      position: relative;
      margin: 200px auto;
      transform-style: preserve-3d;
      perspective: 15000px;
      transition: all 5s linear;
      animation: mytest 5s linear infinite normal;
    }

    @keyframes mytest {
      0% {
        transform: rotateX(0deg) rotateY(0deg);
      }

      100% {
        transform: rotateX(360deg) rotateY(360deg);

      }
    }


    .test {
      width: 200px;
      height: 200px;
      position: absolute;
      top: 0;
      left: 0;
      box-shadow: 0 0 10px black;
      border: 1px solid black;

    }

    .test:nth-child(1) {
      background-color: red;
      transform: translateZ(100px);
    }

    .test:nth-child(2) {
      background-color: yellow;
      transform: rotateY(180deg) translateZ(100px);
    }

    .test:nth-child(3) {
      background-color: orange;
      transform: rotateY(90deg) translateZ(100px);

    }

    .test:nth-child(4) {
      background-color: purple;
      transform: rotateY(-90deg) translateZ(100px);

    }

    .test:nth-child(5) {
      background-color: blue;
      transform: rotateX(90deg) translateZ(100px);

    }

    .test:nth-child(6) {
      background-color: orangered;
      transform: rotateX(-90deg) translateZ(100px);

    }
  </style>
相关标签: 3D 动态 立方体