cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <body>
  <div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>
            
          
!
            
              /* VARIABLES & FUNCTIONS */

//Change value to re-orient die
$front-face: 6;

//colors
$dot-color: white;
$face-backgrounds: (
  tomato,
  mediumVioletRed,
  darkViolet,
  royalBlue,
  teal,
  seaGreen
);
@mixin face-bg($num) {
  background: nth($face-backgrounds, $num);
//  background: url('http://lorempixel.com/29#{$num}/29#{$num}/animals/#{$num}') center/cover;
}
$face-opacity: 0.9;

//General size calculations
$max: 96;
$box-size: $max * 0.58vmin;
$face-size: $box-size;
$dot-size: $face-size/6;
$dot-space: $face-size/8;

//dot locations (box-shadow parameters, duped from top-left dot)
@function dupe-dot($x-offset, $y-offset){
  @return
    ($dot-size + $dot-space) * $x-offset
    ($dot-size + $dot-space) * $y-offset
    $dot-color
}
$mid-left: dupe-dot(0,1);
$bottom-left: dupe-dot(0,2);
$center: dupe-dot(1,1);
$top-right: dupe-dot(2,0);
$mid-right: dupe-dot(2,1);
$bottom-right: dupe-dot(2,2);


//face placement
$face-rotate-axis: (
  X,
  Y,
  X,
  X,
  Y,
  X
);

$face-rotate-deg: (
  0,
  90deg,
  90deg,
  -90deg,
  -90deg,
  180deg
);

//Face/die rotation shortcut. Positive multiplier for faces, negative for die
@function rotation-by-face($num, $multiplier: 1) {
  $rotate-axis: "rotate" + nth($face-rotate-axis,$num);
  $degrees: nth($face-rotate-deg,$num);
  @return #{$rotate-axis + '(' + $degrees * $multiplier + ')'};  
}

//place faces on die (default orientation with 1 in front)
@mixin place-face($num) {
  transform: rotation-by-face($num) translateZ(#{$face-size/2});
}

//orient die by face value plus optional tilt
@function orient-die($num, $tilt: rotateX(-10deg) rotateY(10deg)) {
   @return rotation-by-face($num, -1) $tilt; 
}

@keyframes rotate-through-numbers {
    0%   {transform: orient-die(1);}
    17%  {transform: orient-die(2);}
    33%  {transform: orient-die(3);}
    50%  {transform: orient-die(4);}
    67%  {transform: orient-die(5);}
    84%  {transform: orient-die(6);}
    100% {transform: orient-die(1);}
}

$anim-duration: 6s;

@mixin start-position {
  animation-delay: $anim-duration / -6 * ($front-face - 1);
}



/* STYLES */

body {
  height: $max * 1vmin;
  width: $max * 1vmin;
  margin: 2vmin auto;
  &:before {
    font-family: sans-serif;
    content: 'Mouse over or touch the cube to see it move';
    @media (pointer: coarse), -moz-touch-enabled {
    content: 'Tap the cube to see it move. Tap the background to stop.'
    }
    @media (pointer: fine), not -moz-touch-enabled {
    content: 'Mouse over the cube to see it move.'
    }
  }
}
  
body > div {
  position: absolute;
  top: calc(50% - #{$box-size/2});
  left: calc(50% - #{$box-size/2});
  width: $box-size;
  height: $box-size;
  transform-style: preserve-3d;
  animation: rotate-through-numbers #{$anim-duration} infinite;
  @include start-position;
  animation-play-state: paused;
  &:hover {
    animation-play-state: running;
  }
}

div > div {
  display: block;
  position: absolute;
  top: calc(50% - #{$face-size}/2);
  left: calc(50% - #{$face-size}/2);
  width: $face-size;
  height: $face-size;
  opacity: $face-opacity;
  transform-origin: center center;
  //creates upper-left dot
  &:before {
    content: '';
    display: block;
    position: absolute;
    top: $dot-space;
    left: $dot-space;
    width: $dot-size;
    height: $dot-size;
    border-radius: 50%;
    background: $dot-color;
  }
}


div > div:nth-of-type(1) {
  @include place-face(1);
  @include face-bg(1);
  &:before {
    background: transparent;
    box-shadow: $center;
  }
}


div:nth-of-type(2) {
  @include place-face(2);
  @include face-bg(2);
  &:before {
    box-shadow: $bottom-right;
  }
}


div:nth-of-type(3) {
  @include place-face(3);
  @include face-bg(3);
  &:before {
    box-shadow: $center,
                $bottom-right;
  }
}


div:nth-of-type(4) {
  @include place-face(4);
  @include face-bg(4);
  &:before {
    box-shadow: $bottom-left,
                $top-right,
                $bottom-right;
  }
}

div:nth-of-type(5) {
  @include place-face(5);
  @include face-bg(5);
  &:before {
    box-shadow: $bottom-left,
                $center,
                $top-right,
                $bottom-right;
  }
}

div:nth-of-type(6) {
  @include place-face(6);
  @include face-bg(6);
  &:before {
    box-shadow: $mid-left,
                $bottom-left,
                $top-right,
                $mid-right,
                $bottom-right;
  }  
}
            
          
!
999px
Loading ..................

Console