JSFiddle - React, Tailwind, and code Playground
by amindunited
HTML
<div class="container">
<div class="box show-top">
<div class="face front">Front</div>
<div class="face back">Back</div>
<div class="face left">L</div>
<div class="face right">R</div>
<div class="face top">Top</div>
<div class="face bottom">Bottom</div>
</div>
</div>
CSS
.container {
width: 200px;
height: 300px;
position: relative;
perspective: 1000px;
}
.box {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transform-origin: 50% 200px;
/* transform: translateZ(-50px) rotateX(120deg); */
transform: translateZ() rotateX(120deg);
transition: transform 1s;
}
.box .front { background-color: rgba(256, 0, 0, .35); }
.box .back { background-color: rgba(0, 256, 0, .35); }
.box .right { background-color: rgba(0, 0, 256, .35); }
.box .left { background-color: rgba(126, 0, 0, .35); }
.box .top { background-color: rgba(0, 126, 0, .35); }
.box .bottom { background-color: rgba(0, 0, 126, .35); }
.box .face {
display: block;
position: absolute;
border: 2px solid black;
}
.box .front, .box .back { width: 200px; height: 300px; }
.box .right,
.box .left { width: 20px; height: 300px; left: 100px; }
.box .top,
.box .bottom { width: 300px; height: 20px; top: 50px; }
/* .box .front { transform: rotateY( 0deg ) translateZ( 50px ); }
.box .back { transform: rotateX( 180deg ) translateZ( 50px ); }
.box .right { transform: rotateY( 90deg ) translateZ( 150px ); }
.box .left { transform: rotateY( -90deg ) translateZ( 150px ); }
.box .top { transform: rotateX( 90deg ) translateZ( 100px ); }
.box .bottom { transform: rotateX( -90deg ) translateZ( 100px ); } */
.box .back, .box .front {
width: 200px;
height: 300px;
left: 150px;
top: 50px;
line-height: 300px;
font-size: 45px;
}
.box .right,
.box .left {
width: 50px;
height: 300px;
left: 175px;
top:50px;
}
.box .top,
.box .bottom {
width: 200px;
height: 50px;
top: 125px;
left:150px;
}
.box .bottom {
}
.box .front {
transform: translateZ( 25px );
}
.box .back {
transform: rotateX( -180deg ) translateZ( 25px );
}
.box .right {
transform: rotateY( 90deg ) translateZ(...