<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>3D Dönen Küp</title>
</head>
<body>
<div id="stage">
<div id="front" class="plane"><p>@thecodeblanks</p></div>
<div id="back" class="plane"><p>Html</p></div>
<div id="right" class="plane"><p>Css</p></div>
<div id="left" class="plane"><p>Javascript</p></div>
<div id="top" class="plane"><p>Jquery</p></div>
<div id="bottom" class="plane"><p>For You</p></div>
</div>
</body>
</html>
Sign in
Sign in with your free account to like snippets and add them to your favorites.
body {
display: flex;
align-items: center;
justify-content: center;
perspective: 800px;
background-color: transparent;
}
#stage {
width: 200px;
height: 200px;
margin: 50px auto;
transform-style: preserve-3d;
animation: rotate 10s linear infinite;
}
.plane {
position: absolute;
width: 200px;
height: 200px;
border: 2px solid black;
background: rgba(0, 150, 255, 0.5);
opacity: 0.8;
display: flex;
justify-content: center;
align-items: center;
}
.plane p {
color: white;
font-size: 24px;
font-weight: bold;
} /* Yazı stili */
#front {
transform: translateZ(100px);
}
#back {
transform: rotateY(180deg) translateZ(100px);
}
#right {
transform: rotateY(90deg) translateZ(100px);
}
#left {
transform: rotateY(-90deg) translateZ(100px);
}
#top {
transform: rotateX(90deg) translateZ(100px);
}
#bottom {
transform: rotateX(-90deg) translateZ(100px);
}
@keyframes rotate {
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
}
About this snippet
No canvas, no WebGL: this rotating cube is made of six ordinary div elements positioned in 3D space with CSS. Each face carries its own label (HTML, CSS, JavaScript and so on), and the whole cube spins on the X and Y axes in a 10-second loop.
How it works
perspective: 800pxon the parent gives the scene depth; smaller values exaggerate the 3D effect.#stageusestransform-style: preserve-3dso its children keep their positions in 3D instead of being flattened.- Every face is first rotated to face its direction (
rotateY(90deg),rotateX(-90deg)…) and then pushed outwards withtranslateZ(100px), which is half the cube's 200 px width. - The
rotatekeyframes turn the stage from 0° to 360° on both axes withlineartiming for a constant speed.
How to use it
- Copy the HTML structure with the six
.planefaces and the CSS. - To change the size, update
width/heightof#stageand.plane, then set everytranslateZto half of that value. - Replace the text in each
<p>, or put images inside the faces for a product or logo cube. - Change
10sin the animation to speed the rotation up or down.
Tips
Add backface-visibility: hidden to the faces if you use opaque backgrounds. To make the cube interactive, pause it with animation-play-state: paused on hover.
Comments 0
No comments yet. Be the first to comment.