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

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>
  <a href="#" class="branding">
    <img class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/74764/lisa_logo.svg" alt="Logo" />
  <a />

  <nav>
    <!-- Use a real button and not a div for better keyboard functionality and accessibility
         Remove the button styles in CSS 
     -->
    <button class="menu-button" 
            aria-label="Open navigation menu" 
            aria-expanded="false"
            aria-haspopup="true" 
            aria-controls="menu">
      <span class="menu-bar" aria-hidden="true"></span>
      <span class="menu-bar" aria-hidden="true"></span>
      <span class="menu-bar" aria-hidden="true"></span>
    </button>

    <div id="menu" class="menu" role="navigation">
      <a class="menu-link" href="#">Work</a>
      <a class="menu-link active" href="#" >Teach</a>
      <a class="menu-link" href="#">About</a>
      <a class="menu-link" href="#">Contact</a>
    </div>
  </nav>
</header>

<div class="wrapper">
  <p>Make the viewport smaller or larger to see both types of menus.</p>
  <p>The hamburger menu button should be a real button so you can navigate to it with the keyboard. To open the menu click the button, or navigate to the button until it has focus and hit Enter or the Spacebar.</p>
  <p>Here is a <a href="https://lisacatalano.com">link</a> for testing tab order.</p>
</div>
              
            
!

CSS

              
                // Base Styles 
* {
  box-sizing: border-box;
}

body {
  background-color: #061054;
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 1.4em;
  font-weight: 200;
  line-height: 1.5; 
}

a {
  color: white; 
}

.wrapper {
  color: white; 
  padding: 2em;
}

header {
  display: flex;
  justify-content: space-between;
  padding: 1em 2em;
}

.logo {
  width: 200px;
}

header {
  display: flex;
  justify-content: space-between;
  padding: 1em 2em;
}

// Hamburger Menu button to toggle menu display
.menu-button {
  // Don't want button to look like a button
  border: none; 
  background:transparent;
  
  // place in upper right corner
  position: absolute;
  right: 25px;
  top: 35px;
  
  // Don't show menu button on large screens
  @media (min-width: 900px) {
    display: none;
  }
  
  // When open, change button to an X for closing menu 
  &.open {
    span:first-child {
      transform: rotate(45deg) translate(8px, 8px);
    }

    span:nth-child(2) {
      display: none;
    }

    span:nth-child(3) {
      transform: rotate(-45deg);
    }
  }
}

// 'hamburger' bars
.menu-bar {
  display: block;
  width: 35px;
  height: 4px;
  background-color: white;
  border-radius: 2px;
  margin-bottom: 7px;
  
  transition: transform 0.2s;
}


// Main menu navigation
// Mobile first - links are hidden off to right on small screen until user opens menu 
.menu {
  position: fixed;
  top: 100px;
  right: -100%;
  background: white;
  width: 100%;
  height: calc(100vh - 100px);
  padding: 2em;
  transition: all .5s ease-in-out;
  
  // Display menu on larger screens always
  @media (min-width: 900px) {
    position: unset;
    background: unset;
    width: auto; 
    height: auto;
    padding: 0;
    display: flex;
  }

  // When user clicks, menu is opened with 'open' class
  &.open {
    display: flex;
    flex-direction: column;
    right: 0;
  }
}

// Individual Link styles (mobile first)
.menu-link {
  text-decoration: none; 
  display: block;
  padding: 0.2em;
  color: black;
  border-bottom: 1px solid transparent; // Prevent jumping on hover. Always take space
  border-top: 1px solid transparent; // Prevent jumping on hover. Always take space
  
  @media (min-width: 900px) {
    padding: 5px;
    margin: 0.5em;
    color: white; 
  }
  
  &:hover, 
  &:focus {
    background-color: #eee;
    border-top: 1px solid #aaa;
    border-bottom: 1px solid #aaa;

    @media (min-width: 900px) {
      background-color: unset;
      border-top: 1px solid transparent;
      border-bottom: 1px solid white;
    }
  }
}

.active {
  font-weight: bold;
  
  &:hover {
    cursor: default; 
    border-bottom: 1px solid transparent; 
    border-top: 1px solid transparent; 
    background-color: unset; 
  }
}

// Don't animate transition between mobile menu when resizing window 
.transition-stop * {
  transition: none !important;
}

              
            
!

JS

              
                let toggleMenuBtn = document.querySelector('.menu-button');
let menu = document.querySelector('#menu');

function toggleTabindex(value) {
  let menuItems = menu.querySelectorAll('.menu-link');
  menuItems.forEach((item) => item.setAttribute('tabindex', value));
}

function toggleMenu(e) {
  toggleMenuBtn.classList.toggle('open');
  menu.classList.toggle('open');  

  // Hide outline after clicking, but don't hide when using the keyboard
  if (e.screenX !== 0 && e.screenY !== 0) {
    toggleMenuBtn.blur();
  }

  let ariaAttribute = toggleMenuBtn.getAttribute('aria-expanded');
  if (ariaAttribute === 'false') {
    toggleMenuBtn.setAttribute('aria-expanded', 'true');  
    toggleTabindex(0);
  } else {
    toggleMenuBtn.setAttribute('aria-expanded', 'false');
    toggleTabindex(-1);
  }
}

toggleMenuBtn.addEventListener('click', toggleMenu);

// On small screens, hide menu items from tab order until menu opens
if (window.innerWidth < 900) {
  toggleTabindex(-1);  
}

// This is to avoid animating the menu transitions when window size changes 
window.addEventListener("resize", () => {
  document.body.classList.add('transition-stop');
  clearTimeout(resizeTimer);
  var resizeTimer = setTimeout(function() {
    document.body.classList.remove('transition-stop');
  }, 300);
});
              
            
!
999px

Console