Kostka 3D

Jak zrobić kostkę 3D w HTML i CSS?

1
2
3
4
5
6

HTML

<div id='container'>
<div id='cube'>
<div class='face front'>1</div>
<div class='face back'>2</div>
<div class='face left'>3</div>
<div class='face right'>4</div>
<div class='face top'>5</div>
<div class='face bottom'>6</div>
</div>
</div>  
                        

CSS

#container
{
    width: 250px;
    height: 250px;
    border: 1px dotted black;
    position: relative;
    perspective: 1000px;
}
#cube
{
    position: absolute;
    width:100%;
    height:100%;
    transform-style: preserve-3d;
    animation: go_round 5s ease 0s 
      infinite alternate;
}
@keyframes go_round
{
   from
   {

   }
   to
   {
       transform:rotateX(360deg)
        rotateY(360deg);
   }
}
.face
{
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 100px;
    font-weight: bold;
    color: white;
}
.face:nth-child(n)
{
   border-radius: 40px;
}
.front
{
    background-color:red;
    transform: translateZ(125px);
}
.back
{
    background-color:yellow;
    transform: rotateX(180deg) 
     translateZ(125px);
}
.left
{
    background-color:green;
    transform: rotateY(-90deg) 
     translateZ(125px);
}
.right
{
    background-color:blue;
    transform: rotateY(90deg) 
     translateZ(125px);
}
.top
{
    background-color:orange;
    transform: rotateX(90deg) 
     translateZ(125px);
}
.bottom
{
    background-color:purple;
    transform: rotateX(-90deg) 
     translateZ(125px);
}