Cube Animation

Home / Web Code Snippet / Cube Animation

Cube Animation


                                                          https://youtube.com/shorts/q5bDJ0uwZKM?si=4C44oynTQcKkYfkY

HTML CODE:-
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>
    <div class="container">
        <div>
            <span style="--i:0;"></span>
            <span style="--i:1;"></span>
            <span style="--i:2;"></span>
            <span style="--i:3;"></span>
        </div>
    </div>
</body>
</html>
CSS CODE:-
body{
            padding: 0px;
            margin: 0px;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: black;
        }
        .container{
            position: relative;
            width: 200px;
            height: 200px;
            transform-style: preserve-3d;
            transform: rotate(-30deg);
            animation: animate 4s linear infinite;
        }
        @keyframes animate{
            0%{
                transform: rotateX(-30deg) rotateY(0deg);
            }
            100%{
                transform: rotateX(-30deg) rotateY(360deg);
            }
        }
        .container div{
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            transform-style: preserve-3d;
        }
        .container div span{
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            width: 100%;
            box-shadow: 0px 0px 50px cyan;
            background: linear-gradient(#151515, cyan);
            transform: rotateY(calc(90deg *var(--i))) translateZ(100px);
        }