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

              
                <html>
<body>
  <span id="hamburger-icon" aria-hidden="true"></span>
  <button id="menu-toggle" name="menu-toggle" aria-haspopup="true" aria-expanded="false" aria-controls="flyout-menu" class="visually-hidden">
  Menu
  </button>
</label>
  <header>Site Name</header>
   <nav id="flyout-menu" aria-hidden="true">
      <ul>
         <li><a href="#">Menu Item</a></li>
         <li><a href="#">Menu Item</a></li>
         <li><a href="#">Menu Item</a></li>
         <li><a href="#">Menu Item</a></li>
      </ul>
   </nav>
</body>
</html>
              
            
!

CSS

              
                * { 
-webkit-box-sizing: border-box; 
-moz-box-sizing: border-box; 
-o-box-sizing: border-box; 
box-sizing: border-box; 
} 

html,body { 
  height: 100%; 
  overflow: hidden; 
  font-family: Helvetica, Arial;
} 

#hamburger-icon { 
  -webkit-touch-callout: none; 
  -webkit-user-select: none; 
  -khtml-user-select: none; 
  -moz-user-select: none; 
  -ms-user-select: none; 
  user-select: none; 
  left: 0px; 
  height:50px; 
  width: 50px; 
  display: block; 
  position: fixed; 
  background: rgba(255,255,255,.0);
  z-index: 1; 
} 

#hamburger-icon:before { 
  content: ''; 
  display: block; 
  position: absolute; 
  height: 2px; 
  width: 24px; 
  left: 13px; 
  top: 18px; 
  background-color: #111; 
  box-shadow: 0 7px 0 #111, 0 14px 0 #111; 
} 

header { 
  width: 100%; 
  position: fixed; 
  left: 0px; 
  background: #e1e1e1; 
  padding: 10px 10px 10px 50px; 
  font-size: 24px; 
  line-height: 30px; 
  z-index: 0; 

  -webkit-transition: .25s ease-in-out; 
  -moz-transition: .25s ease-in-out; 
  -o-transition: .25s ease-in-out; 
  transition: .25s ease-in-out; 
  
}

#flyout-menu {   
  position: fixed; 
  top: 0; 
  left:-350px; 
  height: 100%; 
  width: 350px; 
  background: #eeeeee; 
  overflow-x: hidden; 
  overflow-y: scroll; 
  padding: 20px; 
  
  -webkit-transition: .25s ease-in-out; 
  -moz-transition: .25s ease-in-out; 
  -o-transition: .25s ease-in-out; 
  transition: .25s ease-in-out; 
  
} 

.visually-hidden { 
    position: absolute !important;
    height: 1px; 
    width: 1px;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap; /* added line */
}


#flyout-menu ul { 
  display: none;
  list-style-type: none; 
} 

#flyout-menu ul a { 
  display: block; 
  padding: 10px; 
  color: #111; 
  
} 

body.flyout-open #flyout-menu {  
  left: 0px;
}

body.flyout-open #flyout-menu ul {  
  display: block;
}


body.flyout-open header {
  left: 350px;
}


              
            
!

JS

              
                let body = document.querySelector('body');
let hamburger_icon = document.getElementById('hamburger-icon');
let menu_toggle = document.getElementById('menu-toggle');

//
// Toggle flyout on click of menu button or hamburger icon
//
hamburger_icon.addEventListener('click', toggleFlyout);
menu_toggle.addEventListener('click', toggleFlyout);

//
// Show the menu button if it is focused
//
menu_toggle.addEventListener(
  'focus',
  function() {
    menu_toggle.classList.remove('visually-hidden');  
  }
);  

//
// Hide the menu button if it is unfocused
//
menu_toggle.addEventListener(
  'blur',
  function() {
    menu_toggle.classList.add('visually-hidden');  
  }
);  

//
// Toggle flyout if enter pressed on menu button
//
menu_toggle.addEventListener(
  'keyup', 
  function(e) {    
    if ( e.keyCode == 13) {
      e.preventDefault();  
      showFlyout();
      return false;
    }
  }
);

//
// Hide flyout if escape pressed while it is open
//
body.addEventListener(
  'keyup', 
  function(e) {
    if ( e.keyCode == 27 && body.classList.contains('flyout-open') ) {
      e.preventDefault();
      hideFlyout();
      return false;
    }
  }
);

function showFlyout() {
  
  let menu_toggle = document.getElementById('menu-toggle');
  let flyout = document.getElementById('flyout-menu');
  
  body.classList.add('flyout-open');
  menu_toggle.setAttribute('aria-expanded', true);
  flyout.setAttribute('aria-hidden', false);
  
}

function hideFlyout() {
  
  let menu_toggle = document.getElementById('menu-toggle');
  let flyout = document.getElementById('flyout-menu');
  
  body.classList.remove('flyout-open');
  menu_toggle.setAttribute('aria-expanded', false);
  flyout.setAttribute('aria-hidden', true);
  
}

function toggleFlyout() {
  
  let body = document.querySelector('body');
  let menu_toggle = document.getElementById('menu-toggle');
  let flyout = document.getElementById('flyout-menu');
  
  if ( body.classList.contains('flyout-open') ) {
    hideFlyout();
  }
  else {
    showFlyout();
  }
  
  
}

              
            
!
999px

Console