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

Packages

Add 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 or require. We'll also process your JavaScript with Babel.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

            
              <div class="page">
  <span class="page__name">Mobile Menu Animation</span>
  <span class="page__hint">
    Works better on mobile devices. The hamburger button is comfortably available for both left-handed and right-handed users.
  </span>
  <a href="https://www.youtube.com/watch?v=org6Tmfp3PQ" class="r-link page__link" rel="noopener noreferrer" target="_blank">YouTube video with the coding practice</a>
</div>
<div class="menu">
  <nav class="menu__nav">
    <ul class="r-list menu__list">
      <li class="menu__group">
        <a href="#0" class="r-link menu__link">Home</a>
      </li>
      <li class="menu__group">
        <a href="#0" class="r-link menu__link">About me</a>
      </li>
      <li class="menu__group">
        <a href="#0" class="r-link menu__link">Services</a>
      </li>
      <li class="menu__group">
        <a href="#0" class="r-link menu__link">Portfolio</a>
      </li>
      <li class="menu__group">
        <a href="#0" class="r-link menu__link">Blog</a>
      </li>
      <li class="menu__group">
        <a href="#0" class="r-link menu__link">Contacts</a>
      </li>
    </ul>
  </nav>
  <div class="menu__toggle">
    <button class="r-button menu__hamburger">
      <span class="m-hamburger">
        <span class="m-hamburger__label">Open menu</span>
      </span>
    </button>
  </div>  
</div>
<div class="linkedin">
  <div class="linkedin__container">
    <p class="linkedin__text">I'm looking for my fans which I'll give away everything I know. If you're interested then 👉 <a href="https://www.patreon.com/melnik909" class="linkedin__link" rel="noopener noreferrer" target="_blank">join to me on Patreon!</a></p>
  </div>
</div>

            
          
!
            
              
/*
=====
DEPENDENCES
=====
*/

/* The component will reset button browser styles */

.r-button{
  --uirButtonBackgroundColor: var(--rButtonBackgroundColor, transparent);
  --uirButtonPadding: var(--rButtonPadding, var(--rButtonPaddingTop, 0) var(--rButtonPaddingRight, 0) var(--rButtonPaddingBottom, 0) var(--rButtonPaddingLeft, 0));
  --uirButtonBorderWidth: var(--rButtonBorderWidth, 0);
  --uirButtonBorderStyle: var(--rButtonBorderStyle, solid);
  --uirButtonBorderColor: var(--rButtonBorderColor, currentColor);
  --uirButtonFontFamily: var(--rButtonFontFamily, inherit);
  --uirButtonFontSize: var(--rButtonFontSize,  inherit);
  --uirButtonColor: var(--rButtonColor);

  background-color: var(--uirButtonBackgroundColor);
  padding: var(--uirButtonPadding);

  border-width: var(--uirButtonBorderWidth);
  border-style: var(--uirButtonBorderStyle);
  border-color: var(--uirButtonBorderColor);

  cursor: pointer;

  font-family: var(--uirButtonFontFamily);
  font-size: var(--uirButtonFontSize);
}

.r-button::-moz-focus-inner,
.r-button[type="button"]::-moz-focus-inner,
.r-button[type="reset"]::-moz-focus-inner,
.r-button[type="submit"]::-moz-focus-inner {
  
  /* Remove the inner border and padding in Firefox. */
  
  border-style: none;
  padding: 0;
}

/* The component will reset browser's styles of link */

.r-link{
    --uirLinkDisplay: var(--rLinkDisplay, inline-flex);
    --uirLinkTextColor: var(--rLinkTextColor);
    --uirLinkTextDecoration: var(--rLinkTextDecoration, none);

    display: var(--uirLinkDisplay) !important;
    color: var(--uirLinkTextColor) !important;
    text-decoration: var(--uirLinkTextDecoration) !important;
}

/* The component will reset browser's styles of list */

.r-list{
    --uirListPaddingLeft: var(--rListPaddingLeft, 0);
    --uirListMarginTop: var(--rListMarginTop, 0);
    --uirListMarginBottom: var(--rListMarginBottom, 0);
    --uirListListStyle: var(--rListListStyle, none);

    padding-left: var(--uirListPaddingLeft) !important;
    margin-top: var(--uirListMarginTop) !important;
    margin-bottom: var(--uirListMarginBottom) !important;
    list-style: var(--uirListListStyle) !important;
}

/* Basic styles of the hamburger component */

.m-hamburger{
  --uiHamburgerDisplay: var(--hamburgerDisplay, inline-flex);
  --uiHamburgerWidth: var(--hamburgerWidth, 28px);
  --uiHamburgerHeight: var(--hamburgerHeight, 20px);
  --uiHamburgerThickness: var(--hamburgerThickness, 4px);
  --uiHamburgerBorderRadius: var(--hamburgerBorderRadius, 5px);
  --uiHamburgerBgColor: var(--hamburgerBgColor, currentColor);

  display: var(--uiHamburgerDisplay);
  width: var(--uiHamburgerWidth);
  height: var(--uiHamburgerHeight);

  position: relative;
  text-indent: -9999px;
}

.m-hamburger::before, 
.m-hamburger::after, 
.m-hamburger__label{
  width: 100%;
  height: var(--uiHamburgerThickness);
  border-radius: var(--uiHamburgerBorderRadius);
  background-color: var(--uiHamburgerBgColor);

  position: absolute;
  left: 0;
}

.m-hamburger::before, 
.m-hamburger::after{
  content:"";
}

.m-hamburger::before{
  top: 0;
}

.m-hamburger::after{
  bottom: 0;
}

.m-hamburger__label{
  /* The calculation of middle hamburger button line position */
  
  top: calc(50% - calc(var(--uiHamburgerThickness) / 2));
}

/*
=====
MENU STYLES
=====
*/

.menu{
  --uiMenuCircleSize: var(--menuCircleSize, 100px);
  --uiMenuCircleOffset: var(--menuCircleOffset, 10px);
  --uiMenuCircleBgColor: var(--menuCircleBgColor, currentColor);

  --hamburgerWidth: var(--menuHamburgerWidth, 28px);
  --hamburgerHeight: var(--menuHamburgerHeight, 20px);
  --hamburgerBgColor: var(--menuHamburgerBgColor, #fff);

  box-sizing: border-box;
  width: 100%;

  display: flex;
  flex-direction: column;
  align-items: center;  

  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 9998;
}

.menu__nav{
  box-sizing: border-box;
  width: 100%;
  height: 0;

  transition: opacity .2s ease-out;
  opacity: 0;

  display: flex;
  align-items: flex-end;
  z-index: 2;
}

.menu__list{
  width: 100%;
  max-height: 100%;
  display: none;

  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.menu__toggle{
  box-sizing: border-box;
  width: var(--uiMenuCircleSize);
  height: calc(var(--uiMenuCircleSize) / 2);
  padding: var(--uiMenuCircleOffset);

  flex: none;

  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.menu__toggle::before{
  /*
  1. The font-size property is used to simplify calculations of the element's sizes and position
  2. The negative value for the bottom property need for hiding half of circle. 
  */

  content: "";
  width: 1em;
  height: 1em;
  font-size: var(--uiMenuCircleSize); /* 1 */

  background-color: var(--uiMenuCircleBgColor);
  border-radius: 50%;

  position: absolute;
  bottom: -.5em; /* 2 */
  left: calc(50% - .5em);

  will-change: width, height;
  transition: transform .25s cubic-bezier(0.04, -0.1, 0.29, 0.98),
    width .25s cubic-bezier(0.04, -0.1, 0.29, 0.98),
    height .25s cubic-bezier(0.04, -0.1, 0.29, 0.98);
}

.menu__hamburger::before{
  /* Increase of click button area   */

  content: "";
  width: 100%;
  height: 100%;

  position: absolute;
  top: 0;
  left: 0;
}

/* styles of hamburger's animation */

.m-hamburger::before, 
.m-hamburger::after, 
.m-hamburger__label{
  transition-timing-function: ease;
  transition-duration: .15s;  
}

.m-hamburger::before, 
.m-hamburger::after{
  transition-property: transform;
}

.m-hamburger__label{
  transition-property: transform, opacity;
}

/*
=====
MENU STATES
=====
*/

.menu__hamburger:focus{
  outline: none;
}

.menu_activated{
  height: 100%;
}

.menu_activated .menu__nav{
  height: 100%;
  opacity: 1;

  will-change: opacity;
  transition-duration: .2s;
  transition-delay: .3s;
}

.menu_activated .menu__toggle::before{
  width: 100vmax;
  height: 100vmax;
  transform: translate3d(-50vh, -50vh, 0) scale(5);
  transition-duration: 1s;
}

.menu_activated .menu__list{
  display: block;
}

.menu_activated .m-hamburger::before{
  top: 50%;
  transform: translate3d(0, -50%, 0) rotate(45deg);
}

.menu_activated .m-hamburger::after{
  transform: translate3d(0, -50%, 0) rotate(135deg);
  top: 50%;
}

.menu_activated .m-hamburger__label{
  transform: rotate(-45deg) translate3d(-.285em,-.3em, 0);
  opacity: 0;
}

/*
=====
SETTINGS
=====
*/

:root{
  --colorWhite: #fff;
  --colorMain: #4557bb;
  --rLinkTextColor: var(--colorMain);
  --menuCircleSize: 100px;
  --menuCircleBgColor: var(--colorMain);
  --menuHamburgerWidth: 28px;
  --menuHamburgerHeight: 20px;
  --menuHamburgerBgColor: var(--colorWhite);
}

/*
=====
DEMO
=====
*/

@media (min-width: 768px){

  html{
    font-size: 62.5%;
  }
}

@media (max-width: 767px){

  html{
    font-size: 50%;
  }
}

body{
  display: flex;
  height: 100vh;
  margin: 0;  
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Open Sans, Ubuntu, Fira Sans, Helvetica Neue, sans-serif;
  font-size: 1.6rem;
}

.page{
  max-width: 380px;
  padding: 10px;
  margin: auto;  
  text-align: center;
}

.page__name{
  display: block;
  font-size: 3rem;
  font-weight: 700;
}

.page__hint{
  display: block;
  line-height: 1.45;
  margin-top: 1rem;
}

.menu__group{
  --rLinkTextColor: var(--colorWhite);

  padding: .5rem 3rem; 
  font-size: 3.2rem;
  font-weight: 700;
  text-transform: uppercase;
}

/*
=====
LinkedIn
=====
*/

.linkedin{
  width: 100%;
  background-color: #f0f0f0;
  text-align: center;
  
  position: absolute;
  top: 0;
  left: 0;
}

.linkedin__container{
  max-width: 1000px;
  padding: 10px;
  margin-left: auto;
  margin-right: auto;  
}

.linkedin__text{
  margin-top: 0;
  margin-bottom: 0;
}

.linkedin__link{
  color: #ff5c5c;
}
            
          
!
            
              (function(){
  'use strict';

  class Menu {
    constructor(settings) {
      this.menuNode = settings.menuNode;
    }
    
    toggleMenuState(className) {      
      if (typeof className !== 'string' || className.length === 0) {
        return console.log('you did not give the class for toggleState function');
      } 
      return  this.menuNode.classList.toggle(className);
    }
  }

  const jsMenuNode = document.querySelector('.menu');
  const demoMenu = new Menu ({
    menuNode: jsMenuNode
  });
  
  function callMenuToggle(event) {
    demoMenu.toggleMenuState('menu_activated');
  }
  
  jsMenuNode.querySelector('.menu__hamburger').addEventListener('click', callMenuToggle);
})();
            
          
!
999px

Console