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

              
                <button id="menu-toggle"><i class="fas fa-bars"></i></button>
<nav class="menu" id="menu">
  <ol>
    <li class="menu-item"><a href="#0">Home</a></li>
    <li class="menu-item"><a href="#0">About</a></li>
    <li class="menu-item">
      <a href="#0">Widgets</a>
      <ol class="sub-menu">
        <li class="menu-item"><a href="#0">Big Widgets</a></li>
        <li class="menu-item"><a href="#0">Bigger Widgets</a></li>
        <li class="menu-item"><a href="#0">Huge Widgets</a></li>
      </ol>
    </li>
    <li class="menu-item">
      <a href="#0">Kabobs</a>
      <ol class="sub-menu">
        <li class="menu-item"><a href="#0">Shishkabobs</a></li>
        <li class="menu-item"><a href="#0">BBQ kabobs</a></li>
        <li class="menu-item"><a href="#0">Summer kabobs</a></li>
      </ol>
    </li>
    <li class="menu-item"><a href="#0">Contact</a></li>
  </ol>
</nav>

<p>This is some filler content so you can see the menu in action as you normally would.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc malesuada vehicula augue, non tristique ipsum molestie vel. Fusce a libero ut nisl sollicitudin sodales. Praesent dignissim aliquam dui. Aliquam odio quam, commodo nec scelerisque at, hendrerit ut dolor.</p> 
<p>Sed lobortis urna ac justo placerat, nec ullamcorper nisi tincidunt. Praesent pharetra ut arcu sit amet molestie. Maecenas lobortis, nibh in iaculis dapibus, eros libero iaculis risus, sit amet placerat sapien enim at elit. Quisque porta fermentum nisi suscipit vestibulum.</p> 
<p>Interdum et malesuada fames ac ante ipsum primis in faucibus. In nec elementum enim. Suspendisse vulputate felis massa, ac feugiat metus faucibus quis. Phasellus in felis at turpis porttitor ultrices. Quisque laoreet eleifend consequat.</p>

              
            
!

CSS

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

:root {
  --body-top-spacing: 60px;
  --body-gutter: 20px;
}

body {
  margin: 0;
  padding: var(--body-top-spacing) 0 0;
  font-family: 'Roboto';
  font-size: 18px;
}

#menu-toggle {
  z-index: 100;  
  position: fixed;
  top: 0;
  left: 0;
  padding: 1px var(--body-gutter);
  transform: rotate(0deg);
  transition: transform .3s ease-in-out; 
}

.nav-open #menu-toggle {
  transform: rotate(360deg);
}

.nav-open .menu {
  height: 100%;
  background-color: #333;
  transition: background-color .2s ease 0s;
}

.menu a {
  color: #EEE;
  text-decoration: none;
}

.menu {
  overflow: hidden;
  position: fixed;
  top: 0;
  padding-top: var(--body-top-spacing);
  height: 0;
  width: 100%;
  color: #000;
  background-color: #fff;
  transition: background-color .2s ease, height 0s ease .2s;
  -webkit-font-smoothing: antialiased;
}

ol,
ul {
  margin: 0;
  padding-left: var(--body-gutter);
  list-style-type: none;
}

.menu-item {
  position: relative;
  line-height: 1.4;
  font-size: 23px;
}

ol ol li.menu-item {
  line-height: 0;
  overflow: hidden;
  transition: line-height .4s;
}

ol .menu-item--open ol li.menu-item {
  line-height: 1.4;
}

button {
  border: 0;
  background-color: transparent;
  -webkit-appearance: none;
  font-size: 40px;
  cursor: pointer;
}

.nav-open button {
  color: #fff;
}

.sub-menu__toggle {
  position: absolute;
  top: -3px;
  right: 0;
  font-size: 26px;
  color: #fff;
}

p {
  padding: 0 var(--body-gutter);
  
  &:first-of-type {
    margin-top: 0;
  }
}
              
            
!

JS

              
                const parentMenus = document.querySelectorAll('.sub-menu');
const menuToggle = document.querySelector('#menu-toggle');
const menu = document.querySelector('#menu');

// Variable for tracking whether the menu is displayed or hidden
let isDisplayed = false;

// Loop through the menu and add toggle buttons for all submenus
parentMenus.forEach(function(element) {
  var expandButton = document.createElement('button');  
  expandButton.innerHTML = '+';
  expandButton.dataset.isOpen = 'false';
  expandButton.classList.add('sub-menu__toggle');
  element.parentNode.prepend(expandButton);
});

// Toggle submenu open button being interacted with
const allButtons = document.querySelectorAll('.sub-menu__toggle');
allButtons.forEach(function(el, idx) {
  el.addEventListener('click', function(ev) {
    let subMenuOpen = el.dataset.isOpen;
    if('false' == subMenuOpen) {
      el.innerHTML = '-';
    } else {
      el.innerHTML = '+';
    }
    el.dataset.isOpen = ('true' == subMenuOpen) ? 'false' : 'true';
    el.parentNode.classList.toggle('menu-item--open');
  });
});

// Toggle opening/closing the menu
menuToggle.addEventListener('click', function(event) {
  isDisplayed = !isDisplayed;
  var displayClass = isDisplayed ? 'block' : 'none';
  if(isDisplayed) {
    menuToggle.innerHTML = `<i class="fas fa-times"></i>`;
  } else {
    menuToggle.innerHTML = `<i class="fas fa-bars"></i>`;
  }
  document.body.classList.toggle('nav-open');
});
              
            
!
999px

Console