Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                
.wrapper
  .ripple
  .content
    p.header Material design switch
    ul
      li
        p Some Option 1
        input#test(type='checkbox', hidden)
        label.switch(for='test')
      li
        p Some Option 2
        input#test1(type='checkbox', hidden)
        label.switch(for='test1')
      li
        p Some Option 3
        input#test2(type='checkbox', hidden)
        label.switch(for='test2')
  .footer
    button.button.theme(type='button') Switch Theme
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto);


$grid-step = 0.25rem

$size = $grid-step * 10
$height = $grid-step * 4
$padding = $grid-step
$border-radius = $grid-step / 2
$label = $height + ($padding * 2)

$animation-timing = cubic-bezier(0.4,0,.2,1)
$animation = .28s $animation-timing
$animation-slow = .56s $animation-timing

$color-swatch = #8BC34A
$color-dark-swatch = #80CBC4

$color-thumb-off = #fafafa
$color-dark-thumb-off = #bdbdbd

$color-track-off = rgba(black, 26%)
$color-dark-track-off = rgba(white, 30%)

$color-track-on = rgba($color-swatch, 50%)
$color-dark-track-on = rgba($color-dark-swatch, 50%)


body
  background #eee
  font normal normal normal ($grid-step * 4)/1 'Roboto'
  color #808080


.wrapper
  display table
  position absolute
  top 0
  left 0
  right 0
  bottom 0
  width ($size * 7)
  padding 0
  background #fff
  border-radius $border-radius
  text-align right
  margin auto
  box-shadow 0 ($grid-step * 4) ($grid-step * 10) rgba(black, .3), 0 ($grid-step * 3) ($grid-step * 3) rgba(black, .22)
  overflow hidden
  z-index 100

  & .content
    padding ($grid-step * 6) ($grid-step * 6) ($grid-step * 4)

  & .footer
    padding  0 ($grid-step * 4) ($grid-step * 2)

  & .ripple
    display block
    position absolute
    width 4px
    height 4px
    top 100%
    left 100%
    border-radius 100%
    transition box-shadow $animation-slow
    z-index -1
    will-change transform

  & .header
    display block
    font-size ($size / 2)
    text-align left
    color rgba(black, 84%)
    margin 0
    padding 0
    transition color $animation-slow

  & ul
    display block
    padding 0
    width 100%

    & li
      display block
      padding ($grid-step * 4) 0 0

      & p 
        display inline-block
        line-height ( $label )
        margin 0 ($size / 2) 0 
        vertical-align middle
        transition color $animation-slow
  
  &.dark,
  &.dark .header
    color rgba(white, 84%)

    & .ripple
      box-shadow  inset 0 0 0 ($grid-step * 2) rgba(black, 77%),
                        0 0 0 ($grid-step * 100) rgba(black, 77%)
    & .button 
      color rgba(white, .84)

    & .switch
      background $color-dark-track-off

      &::before
        background $color-dark-thumb-off

    & input:checked + .switch
        background $color-dark-track-on

        &::before
          background $color-dark-swatch
          
        &:active::before
          box-shadow 0 $grid-step ( $height / 2 ) rgba(black, .28),
               0 0 0 ($size / 2) rgba($color-dark-swatch, 0.2)    


.button
  display inline-block
  position relative
  padding 0 ($grid-step * 3)
  height ($grid-step * 9)
  border none
  margin ($grid-step * 2) 0
  cursor pointer
  border-radius 2px
  font-size ($grid-step * 4)
  text-transform uppercase
  text-decoration none
  color rgba(black, .84)
  background none
  transition box-shadow $animation,
             color $animation
  outline none

  &:hover
    box-shadow 0 3px 6px rgba(black, .2),
               0 3px 6px rgba(black, .28)
  &:active
    box-shadow 0 10px 20px rgba(black, .19),
               0 6px 6px rgba(black, .23)


.switch
  display inline-block
  position relative
  width ( $size )
  height ( $height )
  border-radius ( $height / 2 )
  background $color-track-off
  transition background $animation
  vertical-align middle
  cursor pointer

  &::before
    content ''
    position absolute
    top ( - $padding )
    left ( - $padding )
    width ($label)
    height ($label)
    background $color-thumb-off
    box-shadow 0 $grid-step ( $height / 2 ) rgba(0,0,0,.28)
    border-radius 50%
    transition left $animation, 
               background $animation,
               box-shadow $animation
  
  &:active::before
    box-shadow 0 $grid-step  ( $height / 2 ) rgba(black, .28),
               0 0 0 ($size / 2) rgba(#808080, .1)
      
      
input:checked + .switch
  background $color-track-on
  
  &::before
    left ( $size - $label + $padding )
    background $color-swatch 
  
  &:active::before
    box-shadow 0 $grid-step ( $height / 2 ) rgba(black, .28),
               0 0 0 ($size / 2) rgba($color-swatch, 0.2)  
      
      
      
              
            
!

JS

              
                const wrapper = document.querySelector('.wrapper');
const button = document.querySelector('.button');
const ripple = document.querySelector('.ripple');
  
button.addEventListener('click', (e) => {
  let top = button.offsetTop + e.offsetY;
  let left = button.offsetLeft + e.offsetX;
    
  Object.assign(ripple.style, {
    top: `${top}px`,
    left: `${left}px` 
  });
    
  wrapper.classList.toggle('dark');
});

              
            
!
999px

Console