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

              
                <header class="header">

  <h1 class="header__title">Mobile Nav</h1>

  <svg class="header__toggle toggle toggle--open" width="26" height="20" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path class="toggle__path" d="M0 18a1 1 0 011-1h24a1 1 0 110 2H1a1 1 0 01-1-1zM0 10a1 1 0 011-1h24a1 1 0 110 2H1a1 1 0 01-1-1zM0 2a1 1 0 011-1h24a1 1 0 110 2H1a1 1 0 01-1-1z" fill="#fff"></path>
  </svg>

  <nav class="nav">
    <ul class="nav__list">
      <li class="nav__item">
        <svg class="nav__toggle toggle toggle--close" width="26" height="20" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path class="toggle__path" d="M3.707 19.092a1 1 0 010-1.414L20.677.708a1 1 0 111.415 1.413l-16.97 16.97a1 1 0 01-1.415 0z" fill="#fff"></path>
          <path class="toggle__path" d="M3.707.707a1 1 0 011.414 0l16.97 16.97a1 1 0 11-1.414 1.415L3.707 2.122a1 1 0 010-1.415z" fill="#fff"></path>
        </svg>
      </li>
      <li class="nav__item">
        <a class="nav__link" href="#">Home</a>
      </li>
      <li class="nav__item">
        <a class="nav__link" href="#">About</a>
      </li>
      <li class="nav__item">
        <a class="nav__link" href="#">Services</a>
      </li>
      <li class="nav__item">
        <a class="nav__link" href="#">Testimonials</a>
      </li>
      <li class="nav__item">
        <a class="nav__link" href="#">Contact</a>
      </li>
    </ul>
  </nav>

</header>
              
            
!

CSS

              
                *,::after,::before {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
}

.toggle {
  cursor: pointer;
}

.header {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 650px;
  background-image: linear-gradient(-14deg, rgba(0, 19, 39,.45), rgba(24, 24, 24,.65)), url('https://images.unsplash.com/photo-1502033491742-0e11fb057e16?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=9bc0ec5be8f30ca2719b36ca0b270159&auto=format&fit=crop&w=2089&q=80');
  background-size: cover;
  background-position: 44.5% center;
  color: #fff;
  font-family: 'Overlock', cursive;
  text-transform: uppercase;

  &__title {
    font-size: 2.5rem;
    letter-spacing: 2.5px;
  }

  &__toggle {
    position: absolute;
    top: 1em;
    right: 1em;
  }
}

.nav {
  $nav: &; // This makes sure we can refer back to the nav once inside &--open

  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  overflow: hidden;
  pointer-events: none; // Stops clicks registering on the nav when it's not opened

  &:before,
  &:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    background-color: #2b2b2b;
    z-index: 5;
    transition-property: transform;
    transition-duration: .5s;
    transition-timing-function: ease-in-out;
    transition-delay: .65s;
  }
  
  &:before {
    transform: translate(-100%);
  }

  &:after {
    right: 0;
    transform: translate(100%);
  }
  
  &__list {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    height: 100%;
    z-index: 10;

    // Reset default UL styles
    margin: 0;
    padding: 0;
    list-style: none;
  }

  &__item {
    margin: 0;
    opacity: 0;
    transition-property: opacity;
    transition-duration: .5s;
    transition-delay: 0s;
  }

  &__link {
    color: #fff;
    text-decoration: none;
  }
  
  &--open {
    pointer-events: auto; // Lets clicks be registered

    &:before,
    &:after {
      transform: translate(0); // Brings in the curtains
      transition-delay: .0s;
    }

    #{$nav}__item {
      opacity: 1;
      transition-delay: .65s;
    }
  }
}
              
            
!

JS

              
                document.addEventListener('click', event => {
    const { target } = event;

    if (target.closest('.toggle')) {
        const nav = document.querySelector('.nav');

        nav.classList.toggle('nav--open');
    }
});
              
            
!
999px

Console