纯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>旋转立方体</title>
    <style>
    *{
        margin:0;
        padding:0;
    }
    body{
        background: #222;
    }
    div.wrap{
        width:200px;
        perspective: 1000px; 
        position: absolute;
        top:50%;
        left:50%;
        transform:translateX(-50%) translateY(-50%);
    }
    .cube{
        width:200px;
        height: 200px;
        position: relative;
        transform-style:preserve-3d;
        transform: rotateX(-50deg) rotateY(-50deg) rotateZ(0deg);
        animation: move 20s infinite linear;
    }
    .cube>div{
        width:100%;
        height:100%;
        background:black;
        position: absolute;
        box-shadow:0 0 10px currentColor;
        font-size: 50px;
        text-align: center;
        line-height: 200px;
    }
    .cube:hover>div{
        background: currentColor;
        box-shadow: 0 0 30px currentColor;
    }
    .cube .out-front{
        transform: translateZ(100px);
        color:deeppink;
    }
    .cube .out-back{
        transform: translateZ(-100px) rotateY(-180deg);
        color:seagreen;
    }
    .cube .out-left{
        transform: translateX(-100px) rotateY(-90deg);
        color:skyblue;
    }
    .cube .out-right{
        transform: translateX(100px) rotateY(90deg);
        color:lightcoral;
    }
    .cube .out-top{
        transform: translateY(-100px) rotateX(90deg);
        color:lightslategrey;

    }
    .cube .out-bottom{
        transform: translateY(100px) rotateX(-90deg);
        color:gold;

    }
    @keyframes move{
        0%{
            transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
        }
        100%{
            transform: rotateX(360deg) rotateY(720deg) rotateZ(720deg);
        }
        /*from 和 to 也可以*/
    }

    </style>
</head>
<body>
    <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>

效果很好,很漂亮!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值