CSS Shapes Practice: Cube

In this example below you will see how to do a CSS Shapes Practice: Cube with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by goob, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright goob ©
  • HTML
  • CSS
  • JavaScript
    .cube
  - 6.times do
    .side
<!-- Inspired by Scott Kellum's pen: https://codepen.io/scottkellum/pen/NxMWmW -->

<!-- Thank you Ana Tudor (https://codepen.io/thebabydino/) for the optimizations: https://codepen.io/thebabydino/pen/EyzvEN -->

/*Downloaded from https://www.codeseek.co/goob/css-shapes-practice-cube-EyzjKo */
    $l:  .5em; // cube edge
$c: #8eff85 #29ffbb #fffc26 #29ffbb #fa72ff #96e8ff;

body {
  overflow: hidden;
  height: 100vh;
  perspective: 200px;
  margin: 0;
  background-color: #000;
  filter: blur(1vh) contrast(200%);
}

.cube {
  font-size: 17vw;
  position: absolute;
  top: 50%;
  left: 50%;
  transform-style: preserve-3d;
  animation: 6s linear infinite rotate;
}

.side {
  width: $l;
  height: $l;
  position: absolute;
  top: -$l;
  backface-visibility: hidden;
  
  @for $i from 0 to 6 {
    &:nth-child(#{$i + 1}) {
      transform: if($i < 4, rotateY($i*90deg), 
        rotateX(pow(-1, $i)*90deg)) 
        translateZ(.5*$l);
      background: nth($c, $i + 1);
    }
  }
}

@keyframes rotate {
  to {
    transform: rotateY(1turn) rotateX(1turn);
  }
}


/*Downloaded from https://www.codeseek.co/goob/css-shapes-practice-cube-EyzjKo */
    

Comments