CSS3 transform动画 3D旋转立体正方形

CSS3 transform动画 3D旋转立体正方形

在一个大的div里放置六个小div,分别向前后,向左右,向上下移动相等位置,再将平面div旋转,添加animation动画
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>立体正方形</title>
  <style>
    #box {
      margin: 100px auto 0;
      transform-style: preserve-3d;
      width: 300px;
      height: 300px;
      border: 1px solid #ccc;
      position: relative;
      animation: zhuan 5s linear infinite;
    }

    @keyframes zhuan {
      from {
        transform: rotateY(0);
      }

      50% {
        transform: rotateY(180deg) rotateZ(45deg);
      }

      to {
        transform: rotateY(360deg);
      }
    }

    #box>div {
      width: 100%;
      height: 100%;
      position: absolute;
    }

    /* 前方 */
    #box>:nth-child(1) {
      background-color: lightblue;
      transform: translateZ(150px);
    }

    /* 右边 */
    #box>:nth-child(2) {
      background-color: lightcoral;
      transform: translateX(150px) rotateY(90deg);
    }

    /* 左边 */
    #box>:nth-child(3) {
      background-color: lightseagreen;
      transform: translateX(-150PX) rotateY(90deg);
    }

    /* 下方 */
    #box>:nth-child(4) {
      background-color: gold;
      transform: translateY(150px) rotateX(90deg);

    }

    /* 上方 */
    #box>:nth-child(5) {
      background-color: lightslategrey;
      transform: translateY(-150px) rotateX(90deg);

    }

    /* 后方 */
    #box>:nth-child(6) {
      background-color: lightgreen;
      transform: translateZ(-150px);
    }
  </style>
</head>

<body>
  <div id="box">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>

</html>
  • 3
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值