纯CSS实现正方体旋转效果

 效果如图:鼠标hover到物体上时出现特效!

源码如下

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>超绚丽CSS3多色彩发光立方体旋转动画</title>

<style>
*{
      margin:0 auto;
      padding:0;
    }
    html{
      background:#222;
    }
    div.wrap{
      width:200px;
      perspective:1000px;/*景深*/
      position:absolute;
      left:50%;
      top:50%;
      transform: translateX(-50%) translateY(-50%);/*利用位移来处理垂直水平居中*/
    }
    .wrap>div.cube{
      width:200px;
      height:200px;
      position:relative;
      transform-style: preserve-3d;
      transform:rotateX(-50deg) rotateY(-50deg) rotateZ(0deg);/*旋转*/
      animation:move 8s infinite linear;/*动画*/
    }
    /*关键帧*/
    @keyframes move{
      0% {
        transform: rotateX(0deg) rotateY(0deg);
      }
      100% {
        transform: rotateX(360deg) rotateY(360deg);
      }
    }
    .cube>div{
      width:100%;
      height:100%;
      border-radius:20px;
      position:absolute;
      background:#000;
      box-shadow:0 0 10px currentColor;/*currentColor关键字的使用值是 color 属性值的计算值*/
      transition: background 0.4s ease-in-out, box-shadow 0.4s ease-in-out;/*过渡 属性 时间 过渡曲线*/
    }
    .cube:hover>div{
      background:currentColor;
      box-shadow:0 0 20px currentColor;
    }
    .cube div.out-front{
      color: deeppink;
      transform:translateZ(100px);/*转换  位移*/
    }
    .cube div.out-back{
      color: seagreen;
      transform:translateZ(-100px) rotateY(180deg);/*转换 位移 旋转*/
    }
    .cube div.out-left{
      color: skyblue;
      transform:translateX(-100px) rotateY(-90deg);
    }
    .cube div.out-right{
      color: lightcoral;
      transform:translateX(100px) rotateY(90deg);
    }
    .cube div.out-top{
      color: mediumseagreen;
      transform:translateY(-100px) rotateX(90deg);
    }
    .cube div.out-bottom{
      color: dodgerblue;
      transform:translateY(100px) rotateX(-90deg);
    }
</style>
</head>
<body>
</div>
      <div class="wrap">
          <div class="cube">
            <div class="out-front"></div>
            <div class="out-back"></div>
            <div class="out-left"></div>
            <div class="out-right"></div>
            <div class="out-top"></div>
            <div class="out-bottom"></div>
          </div>
      </div>
    </body>
</html>

 

  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值