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

              
                .switch
  .body
  .grip
    .power-leds
      .led
      .led
      .led
      .led
  .tablet
    .tablet__frame
      .tablet__screen
        .logo
  .joycon.joycon--left
    .joycon__sign.joycon__sign--minus
    .joycon__stick.joycon__stick--left
      .joycon__stickCenter
    .joycon__cross.joycon__cross--left
      button.joycon__button.joycon__button--top
        .arrow.arrow--up
      button.joycon__button.joycon__button--left
        .arrow.arrow--left
      button.joycon__button.joycon__button--right
        .arrow.arrow--right
      button.joycon__button.joycon__button--bottom
        .arrow.arrow--down
    .joycon__options.joycon__options--capture
  .joycon.joycon--right
    .joycon__sign.joycon__sign--plus
    .joycon__stick.joycon__stick--right
      .joycon__stickCenter
    .joycon__cross.joycon__cross--right
      button.joycon__button.joycon__button--top
        .letter
          ="X"
      button.joycon__button.joycon__button--left
        .letter
          ="Y"
      button.joycon__button.joycon__button--right
        .letter
          ="A"
      button.joycon__button.joycon__button--bottom
        .letter
          ="B"
    .joycon__options.joycon__options--home
              
            
!

CSS

              
                // Utilities
$area-width: 90vmin; // Responsive awesomeness!
$border-width: 0.005em;
$offset: .25em;

// Colours
$bg: #f5d76f;
$left-joycon: #5dc0e0;
$right-joycon: #e77366;
$shadow: rgba(0,0,0, .1);
$highlight: rgba(255,255,255, .5);
$black: #2c2b28;
$dark-grey: #403e41;
$grey: #515056;
$light-grey: #6b6b6d;
$white: #c8c9cc;

// Uncomment the block below for "boring grey" Joy-cons
/*
$left-joycon: #6b6b6d;
$right-joycon: #6b6b6d;
//*/

*,
*::before,
*::after { // Styling the borders here makes it easier down the road for a consistent look
  box-sizing: border-box;
  border-color: #{$black};
  border-style: solid;
  border-width: 0;
}

html,
body {
  height: 100%;
  font-size: 16px;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-family: Helvetica, Arial, sans-serif;
  background-color: $bg;
  background-image: linear-gradient(42deg, rgba(0,0,0,.25), rgba(255,255,255,.25));
  background-attachment: fixed;
  overflow: hidden;
}

.switch {
  position: relative;
  width: 1em;
  height: .4372em;
  font-size: $area-width;
}

.body {
  position: absolute;
  left: 13.75%;
  top: 2%;
  bottom: 0;
  width: 72.5%;
  border-width: #{$border-width};
  background-color: #{$grey};
}

.joycon {
  position: absolute;
  top: 0;
  width: 14.45%;
  height: 100%;
  border-width: #{$border-width};
  box-shadow:
    inset 0  .005em 0 #{$shadow},
    inset 0 -.01em  0 #{$shadow},
    inset 0 -.03em  0 #{$shadow};
  animation: joyconSnap .75s ease-out backwards 1;
  
  &--left {
    left: 0;
    background-color: $left-joycon;
    border-radius: 0.0875em 0 0 0.0875em;
    animation-delay: -.25s;
  }
  
  &--right {
    right: 0;
    background-color: $right-joycon;
    border-radius: 0 0.0875em 0.0875em 0;
  }
  
  &__sign {
    position: absolute;
    top: .0325em;
    width: .02em;
    height: .005em;
    background: $black;
    
    &--minus {
      right: .01em;
    }

    &--plus {
      position: absolute;
      left: .01em;

      &::after {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: inherit;
        transform: rotate(90deg);
      }
    }
  }
  
  &__stick {
    position: absolute;
    width: .07377em;
    height: .07377em;
    border-width: #{$border-width};
    border-radius: 50%;
    background-color: $light-grey;
    box-shadow: .005em -.005em 0 .0025em #{$shadow};
    
    &::before,
    &::after {
      content: '';
      position: absolute;
      left: calc(50% - #{$border-width/2});
      top: 0;
      width: $border-width;
      height: 100%;
      background-color: $black;
    }
    
    &::after {
      transform: rotate(90deg);
    }
    
    &--left {
      left: .035em;
      top: .07377em;
    }
    
    &--right {
      right: .035em;
      top: .1913em;
    }
  }
  
  &__stickCenter {
    position: absolute;
    left: 10%;
    top: 10%;
    width: 80%;
    height: 80%;
    border-width: #{$border-width};
    border-radius: 50%;
    background-color: $light-grey;
    box-shadow: inset #{$border-width/2} -#{$border-width/2} 0 #{$highlight};
    z-index: 1; // To pass the element over the parent's ::after
  }
  
  &__cross {
    position: absolute;
    width: .0875em;
    height: .0875em;
    transform: rotate(45deg);
    
    &--left {
      right: .02em;
      top: .183em;
    }
    
    &--right {
      left: .02em;
      top: .0656em;
    }
  }
  
  &__button {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    width: .038em;
    height: .038em;
    border-width: $border-width;
    border-radius: 50%;
    box-shadow: inset #{$border-width * 0.5} #{$border-width * -0.5} 0 #{$highlight};
    transform: rotate(-45deg);
    transition: box-shadow 100ms ease-in-out;

    &:active {
      box-shadow: inset #{$border-width * -0.5} #{$border-width * 0.5} 0 #{$highlight};
    }

    .joycon__cross--left & {
      background-color: $light-grey;
    }

    .joycon__cross--right & {
      background-color: $dark-grey;
    }
    
    &--top {
      left: 0;
      top: 0;
    }

    &--left {
      left: 0;
      bottom: 0;
    }

    &--right {
      right: 0;
      top: 0;
    }
    
    &--bottom {
      right: 0;
      bottom: 0;
    }
  }

  &__options {
    position: absolute;
    top: .3em;
    width: .035em;
    height: .035em;
    border-width: $border-width;
    background-color: $light-grey;
    
    &--capture {
      right: .025em;
      
      &::after {
        content: '';
        position: absolute;
        left: 10%;
        top: 10%;
        width: 80%;
        height: 80%;
        border-radius: 50%;
        background-color: $black;
      }
    }
    
    &--home {
      left: .025em;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      
      &::before,
      &::after {
        content: '';
        transform: translateY(-.001em);
      }
      
      &::before {
        width: 0;
        height: 0;
        border-width: 0 #{$border-width*2} #{$border-width*2} #{$border-width*2};
        border-color: transparent transparent #{$black} transparent;
      }
      
      &::after {
        width: 50%;
        height: 33%;
        border-width: 0 #{$border-width/2} #{$border-width/2} #{$border-width/2};
      }
    }
  }
}

@keyframes joyconSnap {
  from {
    transform: translateY(-100%);
  }
}

.arrow {
  width: 0;
  height: 0;
  
  &--up {
    border-width: 0 #{$border-width*1.5} #{$border-width*2} #{$border-width*1.5};
    border-color: transparent transparent #{$black} transparent;
  }
  
  &--left {
    border-width: #{$border-width*1.5} #{$border-width*2} #{$border-width*1.5} 0;
    border-color: transparent #{$black} transparent transparent;
  }
  
  &--right {
    border-width: #{$border-width*1.5} 0 #{$border-width*1.5} #{$border-width*2};
    border-color: transparent transparent transparent #{$black};
  }
  
  &--down {
    border-width: #{$border-width*2} #{$border-width*1.5} 0 #{$border-width*1.5};
    border-color: #{$black} transparent transparent transparent;
  }
}

.letter {
  font-size: .015em;
  line-height: 100%;
  color: #{$white};
}

.tablet,
.body {
  transition: transform .3s ease-out;
}

.tablet {
  position: absolute;
  left: 15%;
  top: 0;
  width: 70%;
  height: 101%;
  border-width: #{$border-width};
  background-color: #{$grey};
  box-shadow: inset 0 -#{$border-width} 0 #{$shadow};
  
  &__frame {
    position: absolute;
    left: $border-width;
    right: $border-width;
    top: #{$border-width*2};
    height: 92.5%;
    border-width: $border-width;
    border-radius: .016em;
    background-color: $dark-grey;
    overflow: hidden;
    
    &::before {
      content: '';
      position: absolute;
      right: .0437em;
      bottom: 0;
      width: .0328em;
      height: $border-width;
      background-color: $black;
    }
    
    &::after { // Reflection
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background-image:
        linear-gradient(
          to right,
          #{$highlight}  0%,
          #{$highlight}  25%,
          transparent    25%,
          transparent    30%,
          #{$highlight}  30%,
          #{$highlight}  68%,
          transparent    68%,
          transparent    100%
        );
      transform-origin: 0 0;
      animation: tabletShine .75s linear .5s both 1;
    }
  }
  
  &__screen {
    position: absolute;
    left: .0437em;
    right: .0437em;
    top: .027em;
    bottom: .027em;
    display: flex;
    justify-content: center;
    align-items: center;
    border-width: $border-width;
    border-radius: $border-width;
    background-color: $white;
  }
}

@keyframes tabletShine {
  0% {
    transform: skewX(-30deg) translateX(-100%);
  }
  100% {
    transform: skewX(-30deg) translateX(150%);
  }
}

.logo {
  display: grid;
  grid-template-columns: 1.1695fr 1fr;
  grid-template-rows: 1fr;
  grid-gap: .01468em;
  width: .15em;
  height: .15em;
  
  &::before,
  &::after {
    content: '';
  }
  
  &::before {
    border: .0125em solid #{$dark-grey};
    border-radius: .038em 0 0 .038em;
    background: radial-gradient(.0315em .0315em at 50% 27%, $dark-grey calc(50% - 1px), transparent 50%);
    animation: logoLeft .5s linear .25s 1 backwards;
  }
  
  &::after {
    border-radius: 0 .038em .038em 0;
    background: radial-gradient(.0315em .0315em at 50% 55.25%, transparent calc(50% - 1px), $dark-grey 50%);
    animation: logoRight .5s linear .25s 1;
  }
}

@keyframes logoLeft {
  0% { transform: translateY(-25%); }
  50% { transform: translateY(25%); animation-timing-function: ease-out; }
  100% { transform: translateY(0); }
}

@keyframes logoRight {
  25% { transform: translateY(0); }
  50% { transform: translateY(25%); animation-timing-function: ease-out; }
  100% { transform: translateY(0); }
}

.grip {
  $grip-ring: 0.0125em;
  
  position: absolute;
  left: 0;
  right: 0;
  top: $offset;
  z-index: 0;
  overflow: visible;
  width: .4372em;
  height: .4372em;
  margin: auto;
  border-width: #{$border-width};
  border-width: 0;
  border-radius: 0.0875em;
  // background-color: $dark-grey;
  background:
    linear-gradient(90deg, transparent calc(30% - 1px), #{$dark-grey} 0, #{$dark-grey} calc(70% + 1px), transparent 0) no-repeat 50% 100% / 100% calc(100% - (#{$grip-ring} + #{$border-width})),
    linear-gradient(90deg, #{$black} 30%, transparent 0, transparent 70%, #{$black} 0) no-repeat 50% 100% / 100% 100%,
    radial-gradient(circle at 0 0, transparent calc(#{$grip-ring} + #{$border-width}), #{$dark-grey} 0, #{$dark-grey} 75%, transparent 0) no-repeat 50% 0 / 40% calc(#{$grip-ring} + #{$border-width} + 2px),
    radial-gradient(circle at 100% 0, transparent calc(#{$grip-ring} + #{$border-width}), #{$dark-grey} 0, #{$dark-grey} 75%, transparent 0) no-repeat 50% 0 / 40% calc(#{$grip-ring} + #{$border-width} + 2px);
  transform: translateY(50vh);
  transition: transform .3s ease-out;
  
  &::before,
  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    z-index: -1;
    width: 32%; // Handle itself is 80% of the width of the visible part of the middle of the grip, which is about 40% of the side length
    height: 90%;
    border-width: #{$border-width};
    border-radius: 50% / 25%;
    background-color: $dark-grey;
    transform-origin: 50% 100%;
  }
  
  &::before {
    left: -30%;
    transform: rotate(15deg);
  }
  
  &::after {
    right: -30%;
    transform: rotate(-15deg);
  }
  
  .power-leds {
    $led-count: 4;
    $led-size: 0.0125em;
    $led-border: $led-size * 0.2;
    $led-powerdown-delay: 2000ms;
    $led-powerdown-start: 4000ms;
    
    position: absolute;
    top: 0;
    bottom: 25%;
    left: 0;
    right: 0;
    
    display: grid;
    gap: #{$led-size};
    margin: auto;
    
    width: 30%;
    height: calc(#{$led-size} * (#{$led-count} + #{$led-count} - 1)); // 4 LEDs, with a gap between each (N-1=3) equaling the same size as an LED = 4+3 = height of 7 LEDs
    
    .led {
      position: relative;
      
      &::before,
      &::after {
        content: '';
        
        position: absolute;
        top: 0;
        
        width: #{$led-size};
        height: #{$led-size};
        
        color: #{$grey};
        border: #{$led-border} solid #{$black};
        background: currentColor;
        
        animation: powerLed 1s steps(1) both;
      }
      
      &::before { left: 0; }
      &::after { right: 0; }
      
      @for $led-index from 1 through $led-count {
        &:nth-child(#{$led-index}) {
          &::before { animation-delay: calc(#{$led-powerdown-start} + #{$led-powerdown-delay * ($led-index + 1)}); }
          &::after { animation-delay: calc(#{$led-powerdown-start} + #{$led-powerdown-delay * 0.5} + #{$led-powerdown-delay * ($led-index + 1)}); }
        }
      }
    }
  }
}

@keyframes powerLed {
  from {
    background: green;
  }
}

// Portable version!
@media screen and (max-width: 767px) {
  .tablet,
  .body {
    transform: translateY(#{$offset * -1});
  }
  
  .joycon--left { animation: joyconLeftDetach 1s ease-out forwards; }
  .joycon--right { animation: joyconRightDetach 1s ease-out .15s forwards; }
  
  .grip {
    transform: translateY(0);
    transition-delay: .25s;
  }
}

@keyframes joyconLeftDetach {
  0% { transform: translateX(0) translateY(0); }
  25% { transform: translateX(0) translateY(#{$offset * -1}) rotate(-9deg); }
  50% { transform: translateX(#{$offset * 1.1}) translateY(#{$offset * -1}); }
  100% { transform: translateX(#{$offset * 1.1}) translateY(#{$offset}); }
}

@keyframes joyconRightDetach {
  0% { transform: translateX(0) translateY(0); }
  25% { transform: translateX(0) translateY(#{$offset * -1}) rotate(9deg); }
  50% { transform: translateX(#{$offset * -1.1}) translateY(#{$offset * -1}); }
  100% { transform: translateX(#{$offset * -1.1}) translateY(#{$offset}); }
}
              
            
!

JS

              
                // Resize your browser window!
// Based on the following shot by Jon E. Allen on dribbble:
// https://dribbble.com/shots/4203534-Switch
              
            
!
999px

Console