I want to create a CSS cube that has 4 sides (front, back, top, bottom) and it rotates up (or down) constantly only on X axis. But for some reason I can't align all the 4 sides so it looks like a cube. Here's my markup:
<div class="cube">
<div class="front">
<h1>Front</h1>
</div>
<div class="bottom">
<h2>Bottom</h2>
</div>
<div class="top">
<h2>Top</h2>
</div>
<div class="back">
<h2>Back</h2>
</div>
And my CSS:
body {
color: rgb(6, 106, 117);
text-transform: uppercase;
font-family: sans-serif;
font-size: 100%;
background: #F4F6F8;
padding: 3em 0 0 0;
line-height: 62px;
-webkit-perspective: 1000px; /* <-NB */
}
.cube {
width: 30%;
text-align: center;
margin: 0 auto;
height: 100px;
-webkit-transform-style: preserve-3d;
-webkit-animation: rotate-cube 10s linear infinite;
}
.front, .bottom, .top, .back {
background: rgb(247, 247, 247);
border: 1px solid rgba(147, 184, 189, .8);
-webkit-border-radius: 5px;
-webkit-box-shadow: 0 5px 20px rgba(105, 108, 109, .3), 0 0 8px 5px rgba(208, 223, 226, .4) inset;
height: 100px;
}
.front {
-webkit-transform: translateZ(50px);
}
.bottom {
-webkit-transform: rotateX(-90deg) translateZ(-50px);
transform: rotateX(-90deg) translateZ(-50px);
}
.top {
-webkit-transform: rotateX(90deg) translateZ(-50px);
}
.back {
-webkit-transform: rotateX(180deg) translateZ(-50px);
}
@-webkit-keyframes rotate-cube {
0%{-webkit-transform: rotateX(0deg);}
10%{-webkit-transform: rotateX(90deg);}
40%{-webkit-transform: rotateX(180deg);}
60%{-webkit-transform: rotateX(270deg);}
90%{-webkit-transform: rotateX(360deg);}
100{-webkit-transform: rotateX(360deg);}
}
Here's a JSFiddle. Don't mind the animation itself, I know it's not pretty, but it's still a work in progress. For now I only want to align all the 4 sides properly.
What did I do wrong and how can I align all the 4 sides?