css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              .switch
  .body
  .grip
  .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
      .joycon__button.joycon__button--top
        .arrow.arrow--up
      .joycon__button.joycon__button--left
        .arrow.arrow--left
      .joycon__button.joycon__button--right
        .arrow.arrow--right
      .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
      .joycon__button.joycon__button--top
        .letter
          ="X"
      .joycon__button.joycon__button--left
        .letter
          ="Y"
      .joycon__button.joycon__button--right
        .letter
          ="A"
      .joycon__button.joycon__button--bottom
        .letter
          ="B"
    .joycon__options.joycon__options--home
            
          
!
            
              // 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/2} -#{$border-width/2} 0 #{$highlight};
    transform: rotate(-45deg);

    .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 49%, 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 49%, $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 {
  position: absolute;
  left: 0;
  right: 0;
  top: $offset;
  width: .175em;
  height: 100%;
  margin: auto;
  border-width: #{$border-width};
  background-color: $dark-grey;
  transform: translateY(50vh);
  transition: transform .3s ease-out;
  
  &::before,
  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    width: 80%;
    height: 90%;
    border-width: #{$border-width};
    border-radius: 50% / 25%;
    background-color: $dark-grey;
    transform-origin: 50% 100%;
    z-index: -1;
  }
  
  &::before {
    left: -150%;
    transform: rotate(15deg);
  }
  
  &::after {
    right: -150%;
    transform: rotate(-15deg);
  }
}

// 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}); }
}
            
          
!
            
              // Resize your browser window!
// Based on the following shot by Jon E. Allen on dribbble:
// https://dribbble.com/shots/4203534-Switch
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console