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

              
                <div class="page">
  <span class="page__name">Mobile Menu Animation</span>
  <span class="page__hint">
    Push the button below to see the animation
  </span>
</div>
<div class="menu">
  <nav id="main-menu" class="menu__nav">
    <ul class="menu__list r-list">
      <li class="menu__group" role="none">
        <a href="#0" class="menu__link r-link">Home</a>
      </li>
      <li class="menu__group" role="none">
        <a href="#0" class="menu__link r-link">About me</a>
      </li>
      <li class="menu__group" role="none">
        <a href="#0" class="menu__link r-link">Services</a>
      </li>
      <li class="menu__group" role="none">
        <a href="#0" class="menu__link r-link">Portfolio</a>
      </li>
      <li class="menu__group" role="none">
        <a href="#0" class="menu__link r-link">Blog</a>
      </li>
      <li class="menu__group" role="none">
        <a href="#0" class="menu__link r-link">Contacts</a>
      </li>
    </ul>
  </nav>
  <button class="menu__toggle r-button" type="button" aria-controls="main-menu" aria-expanded="false">
    <span class="menu__hamburger m-hamburger">
      <span class="m-hamburger__label">
        <span class="menu__toggle-hint screen-reader">Open menu</span>
      </span>
    </span>
  </button>
</div>
<div class="linktr">
  <a href="https://cssisntmagic.substack.com" target="_blank" class="linktr__goal r-link">Subscribe on my email newsletter with CSS tips πŸ’ͺπŸ’ͺπŸ’ͺ</a>
</div>

              
            
!

CSS

              
                /*
!!! This demo is being refactored !!!

-- replace .menu:not(.menu_activated) .menu__list{  display: none; } to hidden
-- use :is pseudo-class to simplify selectors 

*/
/*
=====
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{  
  --uiHamburgerThickness: var(--hamburgerThickness, 4px);

  display: var(--hamburgerDisplay, inline-flex);
  width: var(--hamburgerWidth, 28px);
  height: var(--hamburgerHeight, 20px);

  position: relative;
}

.m-hamburger::before, 
.m-hamburger::after, 
.m-hamburger__label{
  width: 100%;
  height: var(--uiHamburgerThickness);
  border-radius: var(--hamburgerBorderRadius, 5px);
  background-color: var(--hamburgerBackgroundColor, currentColor);

  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));
}

/* helper to hide elements that are available only for screen readers. */

.screen-reader{
  width: var(--screenReaderWidth, 1px) !important;
  height: var(--screenReaderHeight, 1px) !important;
  padding: var(--screenReaderPadding, 0) !important;
  border: var(--screenReaderBorder, none) !important;

  position: var(--screenReaderPosition, absolute) !important;
  clip: var(--screenReaderClip, rect(1px, 1px, 1px, 1px)) !important;
  overflow: var(--screenReaderOverflow, hidden) !important;
}

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

.menu{
  --uiMenuCircleSize: var(--menuCircleSize, 6.25rem);
  --uiMenuCircleOffset: var(--menuCircleOffset, 1rem);
  --uiMenuCircleHeight: calc(var(--uiMenuCircleSize) / 2);  
  --uiMenuCircleBackgroundColor: var(--menuCircleBackgroundColor, currentColor);

  --uiMenuHamburgerWidth: var(--menuHamburgerWidth, 1.75rem);
  --uiMenuHamburgerHeight: var(--menuHamburgerHeight, 1.25rem);
  
  --rButtonPaddingTop: calc(var(--uiMenuCircleHeight) - var(--uiMenuHamburgerHeight) - var(--uiMenuCircleOffset));
  
  --hamburgerWidth: var(--uiMenuHamburgerWidth);
  --hamburgerHeight: var(--uiMenuHamburgerHeight);
  --hamburgerBackgroundColor: var(--menuHamburgerBackgroundColor, #fff);

  width: 100%;
  
  display: flex;
  flex-direction: column;
  align-items: center;  

  position: fixed;
  bottom: 0;
  left: 0;
  z-index: var(--menuZindex, 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%;

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

.menu__toggle{
  box-sizing: border-box;
  width: var(--uiMenuCircleSize);
  height: var(--uiMenuCircleHeight);
  flex: none;

  position: relative;
}

.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(--uiMenuCircleBackgroundColor);
  border-radius: 50%;

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

  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);
}

/* 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__toggle:focus,
.menu__link:focus{
  outline: var(--menuHaburgerOutlineOWidth, 2px) solid var(--menuHaburgerOutlineColor);
  outline-offset: var(--menuHaburgerOutlineOffset, 5px);
}

.menu_activated{
  height: 100%;
}

.menu_activated .menu__nav{
  flex-grow: 1;
  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:not(.menu_activated) .menu__list{
  display: none;
}

.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;
  --menuCircleBackgroundColor: var(--colorMain);
  --menuHamburgerBackgroundColor: var(--colorWhite);
  --menuHaburgerOutlineColor: var(--colorMain);
}

.menu_activated{
  --menuHaburgerOutlineColor: var(--colorWhite);
}

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

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

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

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

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

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

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

.linktr{
  order: -1;
  padding: 1.75rem;
  text-align: center;
}

.linktr__goal{
  background-color: rgb(209, 246, 255);
  color: rgb(8, 49, 112);
  box-shadow: rgb(8 49 112 / 24%) 0px 2px 8px 0px;
  border-radius: 2rem;
  padding: .5rem 1.25rem;
}

@media (min-width: 1024px){
  
  .linktr{
    position: absolute; 
    right: 1rem; 
    bottom: 1rem;
  }
}

              
            
!

JS

              
                /*
!!!!!
This code is created to display element's behavior. I'm not a JS expert so don't use it
!!!!!
*/


(function(){
  'use strict';

  class Menu {
    constructor(settings) {
      this.menuRootNode = settings.menuRootNode;
      this.isOpened = false;
    }
    
    changeMenuState(menuState) {
      return this.isOpened = !menuState;
    }
  }
  
  class MenuBurger extends Menu {
    
    constructor(settings) {
      super(settings);
      this.openText = settings.openText;
      this.closeText = settings.closeText;
      this.menuClassesNames = settings.menuClassesNames;
    }
    
    init() {
      let currentMenuState = this.changeMenuState(this.isOpened);
      let toggleHint = this.getCurrentToggleHint(currentMenuState, this.openText, this.closeText);
      let toggleNode = this.menuRootNode.querySelector(`.${this.menuClassesNames.toggleClass}`);
      let menuItems = this.menuRootNode.querySelectorAll(`.${this.menuClassesNames.menuItemClass}`);
      
      this.changeToggleHint(
        toggleHint, 
        this.menuRootNode.querySelector(`.${this.menuClassesNames.toggleHintClass}`)
      );
      this.menuRootNode.classList.toggle(`${this.menuClassesNames.activeClass}`);
      this.setCurrentA11yAttribute(currentMenuState, toggleNode, "aria-expanded");  
      this.getFocusCurrentNode(currentMenuState, toggleNode, menuItems[0]);
    }
    
    changeToggleHint(toggleHint, toggleNode) {
      toggleNode.textContent = toggleHint;
      return toggleHint; 
    }
    
    getCurrentToggleHint(currentMenuState, openText, closeText) {
      return (currentMenuState !== true) ? openText : closeText;
    }
    
    setCurrentA11yAttribute(currentMenuState, toggleNode, attribute) {
      return toggleNode.setAttribute(attribute, currentMenuState);
    }
    
    getFocusCurrentNode(currentMenuState, nodeFirst, nodeSecond) {
      return (currentMenuState !== true) ? this.setFocus(nodeFirst) : this.setFocus(nodeSecond);
    }
    
    setFocus(node) {
      return node.focus();
    }
  }

  const menuClassesNames = {
    rootClass: 'menu',
    activeClass: 'menu_activated',
    toggleClass: 'menu__toggle',
    toggleHintClass: 'menu__toggle-hint',
    menuItemClass: 'menu__link'
  }
  
  const jsMenuNode = document.querySelector(`.${menuClassesNames.rootClass}`);
  const demoMenu = new MenuBurger ({
    menuRootNode: jsMenuNode,
    menuClassesNames: menuClassesNames,
    openText: 'Open menu',
    closeText: 'Close menu'
  });
    
  function toggleMenu(event) {   
      return demoMenu.init();  
  }
  
  jsMenuNode.querySelector(`.${menuClassesNames.toggleClass}`).addEventListener('click', toggleMenu);
})();
              
            
!
999px

Console