Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                .center
  .grid
    mixin selector(name)
      - var radioClass = name + '-radio';
      - var degreeClass = name + '-degree';
      - var arrowClass = name + '-arrow';

      // A set of radio buttons each representing a turn (0°, 90°, 180°, 270°)
      // With CSS we'll always show on top the one that leads to the next state
      input.radio(class=radioClass, type="radio", name=name, value="1", checked)
      input.radio(class=radioClass, type="radio", name=name, value="2")
      input.radio(class=radioClass, type="radio", name=name, value="3")
      input.radio(class=radioClass, type="radio", name=name, value="4")

      // A graphical indicator for the direction of the rotation
      // Consists of an arrow head and a bunch of tail parts
      // The 3D shape is made by CSS
      .arrow(class=arrowClass)
        .head
        - var n = 0;
        while n++ < 30
          .tail-part

      // The label showing up on hover indicating the current degree of the turn
      each val in [1, 2, 3, 4]
        - var id = name + val;
        .degree(id=id, class=degreeClass) #{val * 90 - 90}°

    // The three selectors below the dice
    +selector("y")
    +selector("z")
    +selector("x")

    // The dice with each side
    // The 2D graphics of sides are defined here in SVGs
    // The overall 3D shape is made with CSS
    .dice
      .box
        svg.front
          circle(cx="30", cy="30", r="20")
          circle(cx="75", cy="30", r="20")
          circle(cx="120", cy="30", r="20")
          circle(cx="30", cy="120", r="20")
          circle(cx="75", cy="120", r="20")
          circle(cx="120", cy="120", r="20")
        svg.back
          circle(cx="75", cy="75", r="20")
        svg.left
          circle(cx="30", cy="30", r="20")
          circle(cx="120", cy="120", r="20")
        svg.right
          circle(cx="30", cy="30", r="20")
          circle(cx="120", cy="30", r="20")
          circle(cx="30", cy="120", r="20")
          circle(cx="120", cy="120", r="20")
          circle(cx="75", cy="75", r="20")
        svg.top
          circle(cx="30", cy="30", r="20")
          circle(cx="120", cy="30", r="20")
          circle(cx="30", cy="120", r="20")
          circle(cx="120", cy="120", r="20")
        svg.bottom
          circle(cx="30", cy="30", r="20")
          circle(cx="75", cy="75", r="20")
          circle(cx="120", cy="120", r="20")

    .label Click an axis to rotate

footer
  a(href="https://twitter.com/HunorBorbely", target="_top") @HunorBorbely

              
            
!

CSS

              
                /* 
You can find some of the ideas I used in this pen on the detail page and in the code: https://codepen.io/HunorMarton/details/mdERrLy

Follow me on twitter: https://twitter.com/HunorBorbely
*/

$x-rotation: -20deg;
$y-rotation: -40deg;
$base-color: lighten(#036, 10%);
$font-color: #6f9ceb;

body {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  background-color: #ececec;
  margin: 0;
}

.center {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -180px;
  margin-top: -230px;
}

.grid {
  position: relative;
  display: grid;
  grid-template-columns: 100px 100px 100px;
  grid-template-rows: 280px 100px 20px;
  grid-column-gap: 20px;
  grid-row-gap: 30px;
  border-radius: 10px;

  .dice {
    grid-row: 1;
    grid-column: 1 / -1;
  }

  .y-radio,
  .y-degree,
  .y-arrow {
    grid-row: 2;
    grid-column: 1;
  }

  .z-radio,
  .z-degree,
  .z-arrow {
    grid-row: 2;
    grid-column: 2;
  }

  .x-radio,
  .x-degree,
  .x-arrow {
    grid-row: 2;
    grid-column: 3;
  }

  .radio {
    margin: 0;
    width: 100%;
    height: 100%;
    opacity: 0; // The radio button should be invisible
    z-index: 5; // The radio button must be on top
    cursor: pointer;
  }

  .degree {
    border-radius: 10px;
    color: $font-color;
    font-weight: 900;
    font-size: 1.5em;
    width: 100%;
    height: 100%;
    z-index: 3;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
  }

  .label {
    text-align: center;
    grid-column: 1 / -1;
  }
}

$axis: "y", "z", "x";

// The buttons use a series of checkboxes on top of each other
// In every case the checkbox leading to the next step is visible

// By default all radio buttons are hidden
.degree,
.radio {
  display: none;
}

// Always show the first radio button in the background
// then show the radio button leading for the next state on top of it

// 0° checkbox checked -> Display the checkbox for 90°
// 90° checkbox checked -> Display the checkbox for 180°
// 180° checkbox checked -> Display the checkbox for 270°
// 270° checkbox checked -> Do not display next checkbox but as the 0° is always in the background that will show
@each $a in $axis {
  .#{$a}-radio[value="1"],
  .#{$a}-radio[value="1"]:checked ~ .#{$a}-radio[value="2"],
  .#{$a}-radio[value="2"]:checked ~ .#{$a}-radio[value="3"],
  .#{$a}-radio[value="3"]:checked ~ .#{$a}-radio[value="4"] {
    display: block;
  }
}

// Show the degree on top of the degree in percentage
@each $a in $axis {
  @for $i from 1 through 4 {
    .#{$a}-radio[value="#{$i}"]:checked ~ .#{$a}-radio:hover ~ ##{$a}#{$i},
    .#{$a}-radio:hover ~ .#{$a}-radio[value="#{$i}"]:checked ~ ##{$a}#{$i} {
      display: flex;
    }
  }
}

// Making the dice look 3D
// The rotation of the dice is at the bottom of CSS
.dice {
  display: flex;
  justify-content: center;
  align-items: center;

  transform-origin: center center;
  transform-style: preserve-3d;
  transition: transform 1s;

  .box {
    transform-style: preserve-3d;

    $size: 150px;

    width: $size;
    height: $size;
    position: relative;

    svg {
      background-color: white;
      border: 2px solid lighten($base-color, 5%);
      fill: darken($base-color, 10%);
      position: absolute;
      border-radius: 10px;

      width: $size;
      height: $size;
    }

    // Put the sides of the dice in place
    .front {
      transform: translateX(-$size / 2) translateZ($size / 2);
    }
    .back {
      transform: translateX(-$size / 2) rotateX(180deg) translateZ($size / 2);
    }
    .right {
      transform: translateX(-$size / 2) rotateY(90deg) translateZ($size / 2);
    }
    .left {
      transform: translateX(-$size / 2) rotateY(-90deg) translateZ($size / 2);
    }
    .top {
      transform: translateX(-$size / 2) rotateX(90deg) translateZ($size / 2);
    }
    .bottom {
      transform: translateX(-$size / 2) rotateX(-90deg) translateZ($size / 2);
    }
  }
}

.arrow {
  position: relative;
  transform-origin: center center;
  transform-style: preserve-3d;
  transition: transform 1s;

  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;

  $radius: 40px;
  $width: 30px; // Width of the tail

  .head {
    position: absolute;
    transform: translateZ($radius);

    // Make a thriangle shape
    // https://css-tricks.com/the-shapes-of-css/
    width: 0;
    height: 0;
    border-left: $width/2 + 10 solid transparent;
    border-right: $width/2 + 10 solid transparent;
    border-bottom: $width/2 + 10 solid $base-color;
  }

  .tail-part {
    position: absolute;
    width: $width;
    height: $radius/5;

    // Make the arrow tail look circular
    @for $i from 2 through 31 {
      &:nth-of-type(#{$i}) {
        // Rotate each by a different angle then translate it by circle radius
        transform: rotateX($i * -10deg) translateZ($radius);
        background-color: lighten($base-color, $i * 1%);
      }
    }
  }
}

// Arrow 1
@for $y from 1 through 4 {
  .y-radio[value="#{$y}"]:checked {
    ~ .y-arrow {
      transform: rotateX($x-rotation)
        rotateY($y-rotation)
        rotateZ(-90deg)
        rotateX(($y - 1) * 90deg);
    }
  }
}

// Arrow 2
@for $y from 1 through 4 {
  .y-radio[value="#{$y}"]:checked {
    @for $z from 1 through 4 {
      ~ .z-radio[value="#{$z}"]:checked {
        ~ .z-arrow {
          transform: rotateX($x-rotation)
            rotateY($y-rotation)
            rotateZ(180deg)
            rotateY(($y - 1) * 90deg - 90deg)
            rotateX(($z - 1) * 90deg);
        }
      }
    }
  }
}

// Arrow 3
@for $y from 1 through 4 {
  .y-radio[value="#{$y}"]:checked {
    @for $z from 1 through 4 {
      ~ .z-radio[value="#{$z}"]:checked {
        @for $x from 1 through 4 {
          ~ .x-radio[value="#{$x}"]:checked {
            ~ .x-arrow {
              transform: rotateX($x-rotation)
                rotateY($y-rotation)
                rotateY(($y - 1) * -90deg)
                rotateZ(($z - 1) * 90deg)
                rotateX(($x - 1) * 90deg);
            }
          }
        }
      }
    }
  }
}

// Rotate the dice
@for $y from 1 through 4 {
  @for $z from 1 through 4 {
    @for $x from 1 through 4 {
      .y-radio[value="#{$y}"]:checked
        ~ .z-radio[value="#{$z}"]:checked
        ~ .x-radio[value="#{$x}"]:checked
        ~ .dice {
        transform: rotateX($x-rotation)
          rotateY($y-rotation)
          rotateY(($y - 1) * -90deg)
          rotateZ(($z - 1) * 90deg)
          rotateX(($x - 1) * 90deg);
      }
    }
  }
}

footer {
  position: absolute;
  bottom: 20px;
  font-size: 0.8em;
  text-align: center;
  width: 100%;

  a:visited {
    color: inherit;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console