純CSS實現3D立方體

廢話不多說,上代碼

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>cube</title>
  <style>
    .container {
      width: 50px;
      height: 50px;
      margin: 0 auto;
      margin-top: 200px;
      perspective: 1000px;
    }

    .box {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      transform-style: preserve-3d;
      animation: x 10s linear infinite;
    }

    .box>div {
      width: 50px;
      height: 50px;
      position: absolute;
      top: 0;
      left: 0;
      opacity: .3;
      box-shadow: 0 0 10px 5px #000;
      line-height: 50px;
      text-align: center;
    }

    .box:nth-of-type(1)>div:nth-of-type(1) {
      background: url(http://zmdd95.com/images/2.jpg) no-repeat;
      background-size: 100% 100%;
      transform: rotate(0deg) translateZ(25px);
    }

    .box:nth-of-type(1)>div:nth-of-type(2) {
      background: red;
      transform: rotateX(180deg) translateZ(25px);
    }

    .box:nth-of-type(1)>div:nth-of-type(3) {
      background: green;
      transform: rotateY(-90deg) translateZ(25px);
    }

    .box:nth-of-type(1)>div:nth-of-type(4) {
      background: blue;
      transform: rotateY(90deg) translateZ(25px);
    }

    .box:nth-of-type(1)>div:nth-of-type(5) {
      background: #f67;
      transform: rotateX(90deg) translateZ(25px);
    }

    .box:nth-of-type(1)>div:nth-of-type(6) {
      background: #f92;
      transform: rotateX(-90deg) translateZ(25px);
    }

    @keyframes x {
      from {
        transform: rotate(0deg) rotateX(0deg) rotateY(0deg);
      }
      to {
        transform: rotate(360deg) rotateX(360deg) rotateY(360deg);
      }
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="box">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
    </div>
  </div>
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章