Cubo 3D
Un cubo 3D usando solo CSS… ¯\(ツ)/¯
front
back
right
left
top
bottom
<div class="cube-container"> <div class="cube"> <div class="front">front</div> <div class="back">back</div> <div class="right">right</div> <div class="left">left</div> <div class="top">top</div> <div class="bottom">bottom</div> </div></div>
.cube-container { perspective: 500px; /* Importante para la corrección de la perspectiva */}
.cube { width: 12rem; height: 12rem; --z: 6rem; /* Distancia entre el centro y las caras del cubo */ --duration: 10s; aspect-ratio: 1 / 1; position: relative; transform-style: preserve-3d; animation: rotate var(--duration, 10s) infinite linear; > * { width: 100%; height: 100%; position: absolute; transform: /* Configuración de rotación y traslación */ rotateY(var(--y, 0deg)) rotateX(var(--x, 0deg)) translateZ(var(--z)); backface-visibility: visible; /* visible | hidden */
align-content: center; text-align: center; text-transform: uppercase; background: linear-gradient(in oklch to bottom left, #84cc1670, #22c55e70, #16a34a70); border: 1px solid hsla(72, 86%, 51%, 0.8); }}
.front { --y: 0deg; }.back { --y: 180deg; }.left { --y: 90deg; }.right { --y: -90deg; }.top { --x: 90deg; }.bottom { --x: -90deg; }
@keyframes rotate { from { transform: rotateX(0deg) rotateY(0deg) } to { transform: rotateX(360deg) rotateY(360deg) }}
Fin.