3D正方形

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        @keyframes zhuan {
            from{transform: rotateY(0)}
            50%{transform: rotateY(180deg) rotateX(40deg)}
            100%{transform: rotateY(360deg)}
        }
        #box{
            width: 300px;
            height: 300px;
            border: 2px solid red;
            margin: 100px auto 0;
            position: relative;
            animation: zhuan 3s linear infinite;
            transform-style: preserve-3d;
        }
        #box>div{
            position: absolute;
            left: 0;
            top: 0;
            text-align: center;
            line-height: 300px;
            font-size: 100px;
            width: 100%;
            height: 100%;
        }
        #box>div:nth-child(1){background: lightgreen; transform: translateZ(150px)}
        #box>div:nth-child(2){background: lightblue;transform: rotateY(180deg) translateZ(150px)}
        #box>div:nth-child(3){background: lightcoral;transform: rotateY(-90deg) translateZ(150px)}
        #box>div:nth-child(4){background: lightsalmon;transform: rotateY(90deg) translateZ(150px)}
        #box>div:nth-child(5){background: purple;transform: rotateX(90deg) translateZ(150px)}
        #box>div:nth-child(6){background: pink;transform: rotateX(90deg) translateZ(-150px)}
    </style>
</head>
<body>
<div id="box">
    <div>前</div>
    <div>后</div>
    <div>左</div>
    <div>右</div>
    <div>上</div>
    <div>下</div>
</div>
</body>
</html>

前边的面在z轴上往前移150像素,后边的面直接在z轴上往后移动150像素的话字是反的,所以要先在Y轴上旋转180度,在往后移动(顺序是先旋转再移动)

左边的面在Y轴上旋转-90度,z轴上往前移动150像素,右边和左边相反,右边在Y轴上旋转90度

上边的面在x轴上旋转90像素,z轴上往前移动150像素,下边的面和上边的相反,在z轴上往后移动-150像素

上一篇:Dubbo router路由机制(九)


下一篇:Yii2与layuiadmin整合2