css 3d 魔方模型

效果:
在这里插入图片描述
有空再把它做成真正可以扭的魔方

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3d魔方</title>
    <style>
        .parent {
            width: 700px;
            height: 700px;
            margin: 0 auto;
            position: relative;
            perspective: 500px;
        }
        .big {
            position: absolute;
            width: 300px;
            height: 300px;
            transform-style: preserve-3d;
            /*animation: rotate 3s linear infinite;*/
        }
        .bigBig {
            position: absolute;
            width: 100%;
            height: 100%;
            transform-style: preserve-3d;
            animation: rotate 10s linear infinite;
        }
        .color {
            position: absolute;
            top:  300px;
            left: 300px;
            width: 100px;
            height: 100px;
            transform-style: preserve-3d;
        }

        .color div {
            position: absolute;
            width: 100%;
            height: 100%;
            border-radius: 8px;
            border: white solid 1px;
            opacity: 0.7;
        }
        .color div:nth-child(1){
            transform-origin: left;
            background-color: green;
            transform: rotateY(-90deg);
        }
        .color div:nth-child(2){
             transform-origin: right;
            background-color: blue;
             transform: rotateY(90deg);
         }
        .color div:nth-child(3){
            background-color: red;
            transform-origin: top;
            transform: rotateX(90deg);
        }
        .color div:nth-child(4){
            background-color: pink;
             transform-origin: bottom;
             transform: rotateX(-90deg);
         }
        .color div:nth-child(5){
            background-color: white;
            transform: translateZ(100px);
        }
        .color div:nth-child(6){
            background-color: yellow;
        }


        .big .color:nth-child(1){

        }
        .big .color:nth-child(2){
            transform: translateX(-100px);
        }
        .big .color:nth-child(3){
            /*animation: rotate 3s linear infinite;*/
            transform: translateX(100px);
        }
        .big .color:nth-child(4){
            transform: translateY(-100px);
        }
        .big .color:nth-child(5){
            transform: translateY(100px);
        }
        .big .color:nth-child(6){
            transform: translate3d(100px,100px,0px);
        }
        .big .color:nth-child(7){
            transform: translate3d(100px,-100px,0px);
        }
        .big .color:nth-child(8){
            transform: translate3d(-100px,100px,0px);
        }
        .big .color:nth-child(9){
             transform: translate3d(-100px,-100px,0px);
         }

        .bigBig .big:nth-child(1){
            transform: translateZ(-150px);
            transition: all 3s;
        }
        .bigBig .big:nth-child(2){
            transform: translateZ(-50px);
        }
        .bigBig .big:nth-child(3){
            /*animation: rotate 3s linear infinite;*/
            transform: translateZ(50px);
        }




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

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

    </style>

</head>
<body>
<div class="parent">
    <section class="bigBig">
        <section class="big">
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
        </section>
        <section class="big">
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
        </section>
        <section class="big">
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
            <section class="color">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </section>
        </section>
    </section>


</div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值