code demo
html code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Cube Box Animation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="cube">
<div class="face front"></div>
<div class="face back"></div>
<div class="face right"></div>
<div class="face left"></div>
<div class="face top"></div>
<div class="face bottom"></div>
</div>
</body>
</html>
css code
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: #222;
display: grid;
place-items: center;
height: 100vh;
margin: 0;
perspective: 1000px;
}
.cube {
width: 100px;
height: 100px;
position: relative;
transform-style: preserve-3d;
animation: rotate 5s infinite linear;
}
.face {
position: absolute;
width: 100%;
height: 100%;
opacity: 0.8;
border: 2px solid white;
}
.front {
background: #f00;
transform: translateZ(50px);
}
.back {
background: #0f0;
transform: translateZ(-50px) rotateY(180deg);
}
.right {
background: #00f;
transform: translateX(50px) rotateY(90deg);
}
.left {
background: #ff0;
transform: translateX(-50px) rotateY(-90deg);
}
.top {
background: #f0f;
transform: translateY(-50px) rotateX(90deg);
}
.bottom {
background: #0ff;
transform: translateY(50px) rotateX(-90deg);
}
@keyframes rotate {
from {
transform: rotateX(0) rotateY(0);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
}