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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <header>
  <h2>Sass animated hamburger mixin</h2>
  <p>
    <a href="http://codepen.io/rolandtoth/pen/LypvrV?editors=1100" target="_blank" class="active">Sass</a>
    <a href="http://codepen.io/rolandtoth/pen/rzYPKK?editors=1100" target="_blank">Stylus</a>
    <a href="https://codepen.io/rolandtoth/pen/qXpoMd?editors=1100" target="_blank">LESS</a>
  </p>
</header>


<div class="examples">
  <p>
    <input type="checkbox" id="toggle-defaults" />
    <label for="toggle-defaults"><i></i><span>Defaults</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-custom-size" />
    <label for="toggle-custom-size"><i></i><span>Custom size</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-custom-animation" />
    <label for="toggle-custom-animation"><i></i><span>Custom animation</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-radius" />
    <label for="toggle-radius"><i></i><span>Radius</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-padding" />
    <label for="toggle-padding"><i></i><span>Padding</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-text-on-right" />
    <label for="toggle-text-on-right"><i></i><span>Text on right + align-left style</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-text-on-left" />
    <label for="toggle-text-on-left"><i></i><span>Text on left + align-right style</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-tint" />
    <label for="toggle-tint"><i></i><span>Tint</span></label>
    <em></em>
  </p>
  
  <p>
    <input type="checkbox" id="toggle-solid-background" />
    <label for="toggle-solid-background"><i></i><span>Solid background</span></label>
    <em></em>
  </p>

  <p>
    <input type="checkbox" id="toggle-noanim" />
    <label for="toggle-noanim"><i></i><span>No animation</span></label>
    <em></em>
  </p>
  
  <p class="dark">
    <input type="checkbox" id="toggle-above-dark-background" />
    <label for="toggle-above-dark-background"><i></i><span>Above dark background</span></label>
    <em></em>
  </p>
</div>

<footer>
  <p>
    <a href="https://github.com/rolandtoth/hamburger-mixin" target="_blank">View on GitHub</a>
  </p>
</footer>
              
            
!

CSS

              
                // helper mixin
@mixin hamburger_tint($color: #000, $tint_text: false, $labelselector: '+ label') {
  #{$labelselector} {
    i, &::before, &::after {
      background-color: $color;
    }
    @if $tint_text {
      span {
        color: $color;
      }
    }
  }
}

// main mixin
@mixin hamburger($width: 32px, $thickness: 3px, $gap: 7px, $color: #000, $background: transparent, $tint_text: false, $radius: 0, $radius_background: 0, $anim: 0.25s, $labelselector: '+ label', $padding: 0, $text: 'right', $style: false) {
  $height: ($thickness*3) + ($gap*2);
  @if $background != transparent and $padding == 0 {
    $padding: round(($thickness + $gap) / 1.5);
  }
  display: none;
  #{$labelselector} {
    user-select: none;
    position: relative;
    display: inline-block;
    width: $width;
    height: $height;
    box-sizing: content-box;
    border: $padding solid transparent;
    z-index: 1050;
    line-height: $height;
    white-space: nowrap;
    background: $background;
    border-radius: $radius_background;
    span {
      display: inline-block;
      position: absolute;
      left: 100%;
      margin-top: 1px;
      transition: color $anim;
      margin-left: $padding;
      @if $text == false {
        display: none;
      }
      @elseif $text == 'left' {
        left: auto;
        right: 100%;
        margin-left: 0;
        margin-right: $padding;
      }
      &::before, &::after {
        content: '';
        display: inline-block;
        min-width: 10px;
        width: $width*0.2;
      }
    }
    i, &::before, &::after {
      position: absolute;
      left: 0;
      display: block;
      will-change: transform, background-color;
      width: $width;
      height: $thickness;
      border-radius: $radius;
      transition: transform $anim, background-color $anim;
      backface-visibility: hidden;
      outline: 1px solid transparent; // Firefox jagged animation fix
    }
    i {
      top: $thickness + $gap;
      // hide text
      font-size: 0;
      color: transparent;
      line-height: 0;
      @if $style == 'align-left' {
        max-width: $width * 0.75;
        transform-origin: 66% center;
      } @elseif $style == 'align-right' {
        max-width: $width * 0.75;
        margin-left: $width * 0.25;
        transform-origin: 33% center;
      }
    }
    &::before, &::after {
      content: '';
    }
    &::before {
      top: 0;
    }
    &::after {
      bottom: 0;
    }
    &:hover {
      cursor: pointer;
    }
  }
  &:checked {
    @if $anim != -1 {
      #{$labelselector} {
        i {
          transform: scaleX(0.001);
        }
        &::before {
          transform: translateY($gap + $thickness) rotate(45deg);
        }
        &::after {
          transform: translateY(-($gap + $thickness)) rotate(-45deg);
        }
      }
    }
  }
  @include hamburger_tint($color, $tint_text, $labelselector);
}

// Usage

#toggle-defaults {
  @include hamburger();
}

#toggle-custom-size {
  @include hamburger($width: 50px, $thickness: 1px, $gap: 16px);
}

#toggle-custom-animation {
  @include hamburger($anim: cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.33s);
}

#toggle-tint {
  @include hamburger($color: crimson, $tint_text: true);
  &:checked {
    @include hamburger_tint($color: darkgrey, $tint_text: true);
    &:hover {
      @include hamburger_tint($color: blue, $tint_text: true);
    }
  }
  &:hover {
    @include hamburger_tint($color: green, $tint_text: true);
  }
}

#toggle-radius {
  @include hamburger($width: 40px, $thickness: 6px, $color: coral, $radius: 6px);
}

#toggle-padding {
  @include hamburger($width: 24px, $thickness: 2px, $gap: 5px, $padding: 24px);
  &:hover {
    @include hamburger_tint(orange);
  }
}

#toggle-text-on-left {
  @include hamburger($text: left, $style: 'align-right');
}

#toggle-text-on-right {
  @include hamburger($text: right, $style: 'align-left');
}

#toggle-solid-background {
  @include hamburger($background: #FF6347, $width: 17px, $thickness: 3px, $gap: 4px, $padding: 12px, $color: white, $radius_background: 50%);
}

#toggle-noanim {
  @include hamburger($anim: -1);
}

#toggle-above-dark-background {
  @include hamburger($color: white);
  &:checked {
    @include hamburger_tint($color: #293134, $tint_text: true);
  }
}

// Presentation styles

body {
  padding: 0 20px 20px;
  background: #eaebec;
  font-family: sans-serif;
}
header {
  text-align: center;
}
header, .examples p {
  padding: 12px 0;
  margin: 6px 0;
}
header a, .examples p a {
  display: inline-block;
  margin: 0 6px;
  color: inherit;
}
header a.active, .examples p a.active {
  color: #888;
  text-decoration: none;
}
.examples p {
  line-height: 0;
  background: #fff;
  position: relative;
}
.examples p > span {
  display: inline-block;
  min-width: 320px;
  position: relative;
  top: -5px;
  padding-left: 16px;
}
.examples p.dark {
  color: #fff;
  background: #293134;
}
label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
label span {
  transition: all 0.2s !important;
}
label:not([for="toggle-text-on-left"]):not([for="toggle-text-on-right"]) span {
  display: inline-block !important;
  opacity: 0.3;
}
label:hover span {
  opacity: 1 !important;
}

input {
  ~ em {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: block;
    background: #eaebec;
    transition: all 0.2s;
    transform: scaleX(0);
  }
  &:checked ~ em {
    transform: scaleX(1);
  }
}

footer {
  text-align: center;
  font-size: 13px;
  margin: 24px 0;
  a {
    color: #777;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console