纯css实现3D立方体

   关注公众号,每天都能领外卖红包

​​​​​​​

纯css实现3D立方体特效,通过3D旋转和平移原理实现,话不多说直接贴代码

<html>
<head>
    <style type="text/css">
        body,html{
            margin: 0;
        }
        body{
            display: flex;
            align-items: center;
        }
        #parent{
            margin: 0 auto;
            width: 300px;
            height: 300px;
            position: relative;
            transform: rotate(45deg);
            transform-style: preserve-3d;
            animation: 10s spin linear infinite;
            transition: transform 1s linear;
        }
        #parent_new{
            left: calc(50% - 75px);
            width: 150px;
            height: 150px;
            position: absolute;
            transform: rotate(45deg) ;
            transform-style: preserve-3d;
            animation: 3s spin_new linear infinite;
            transition: transform 0.5s linear;
        }
        #parent>div{
            width: 300px;
            height: 300px;
            position: absolute;
            border: 5px solid #ccc;

        }
        #parent_new>div{
            width: 150px;
            height: 150px;
            position: absolute;
            border: 1px solid #ccc;
            background: black;
            opacity: 0.5;
        }
        #parent>div:nth-child(1){
            transform: translateZ(-150px);
            transition: transform 1s linear;


        }
        #parent>div:nth-child(2){
            transform:rotateY(-90deg) translateZ(150px) ;
            transition: transform 1s linear;
        }
        #parent>div:nth-child(3){
            transform:rotateY(-90deg) translateZ(-150px) ;
            transition: transform 1s linear;

        }
        #parent>div:nth-child(4){
            transform:rotateX(90deg) translateZ(150px) ;
            transition: transform 1s linear;

        }
        #parent>div:nth-child(5){
            transform:rotateX(90deg) translateZ(-150px) ;
            transition: transform 1s linear;

        }
        #parent>div:nth-child(6){
            transform: translateZ(150px);
        }

        #parent_new>div:nth-child(1){
            transform: translateZ(-75px);
            transition: transform 1s linear;

        }
        #parent_new>div:nth-child(2){
            transform:rotateY(-90deg) translateZ(75px) ;
            transition: transform 1s linear;
        }
        #parent_new>div:nth-child(3){
            transform:rotateY(-90deg) translateZ(-75px) ;
            transition: transform 1s linear;

        }
        #parent_new>div:nth-child(4){
            transform:rotateX(90deg) translateZ(75px) ;
            transition: transform 1s linear;

        }
        #parent_new>div:nth-child(5){
            transform:rotateX(90deg) translateZ(-75px) ;
            transition: transform 1s linear;

        }
        #parent_new>div:nth-child(6){
            transform: translateZ(75px);
        }
        @keyframes spin{
             0%{
                 transform: rotateX(0deg) rotateY(0deg);
             }
             100%{
                 transform: rotateX(360deg) rotateY(360deg);
             }

         }
        @keyframes spin_new{
            0%{
                transform: rotateX(0deg) rotateY(0deg);
            }
            100%{
                transform: rotateX(360deg) rotateY(360deg);
            }

        }

    </style>
</head>
<body>
<!--外层立方体-->
<div id="parent">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>

</div>
<!--内层立方体-->
<div id="parent_new">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

</body>
</html>

效果图

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hhzzcc_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值