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 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

              
                <header class="nav-wrapper">
  <nav class="nav" role="navigation">
    <span class="toggleNav">
      <svg class="svg-hamburger" viewBox="0 0 1536 1280" xmlns="http://www.w3.org/2000/svg">
        <path class="svg-hamburger-path" d="M1536 1088v128q0 26-19 45t-45 19H64q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1408q26 0 45 19t19 45zm0-512v128q0 26-19 45t-45 19H64q-26 0-45-19T0 704V576q0-26 19-45t45-19h1408q26 0 45 19t19 45zm0-512v128q0 26-19 45t-45 19H64q-26 0-45-19T0 192V64q0-26 19-45T64 0h1408q26 0 45 19t19 45z"
              fill="rgba(226, 241, 236, 20.85)" />
      </svg>
    </span> 
    <a class="nav__logo" href="#">
      <img class="logo logo-small" id="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/JavaScript-logo.png/480px-JavaScript-logo.png" alt="Logo">
    </a>
    <ul class="nav__list" id="sideNav">
      <div class="nav__list-left">
        <a class="closeBtn">
          <svg class="svg-close" viewBox="0 0 1188 1188" xmlns="http://www.w3.org/2000/svg">
            <path class="svg-close-path" d="M1188 956q0 40-28 68l-136 136q-28 28-68 28t-68-28L594 866l-294 294q-28 28-68 28t-68-28L28 1024Q0 996 0 956t28-68l294-294L28 300Q0 272 0 232t28-68L164 28q28-28 68-28t68 28l294 294L888 28q28-28 68-28t68 28l136 136q28 28 28 68t-28 68L866 594l294 294q28 28 28 68z"
                  fill="rgba(226, 241, 236, 0.85)" />
          </svg>
        </a>
        <li>
          <a class="nav__item" href="#">Home</a>
        </li>
        <li>
          <a class="nav__item" href="#">Link</a>
        </li>
        <li>
          <a class="nav__item" href="#">Second Link</a>
        </li>
        <li>
          <a class="nav__item" href="#">Third Link</a>
        </li>
        <li>
          <a class="nav__item" href="#last-section">Last Section</a>
        </li>
      </div>
      <div class="nav__list-right">
        <div class="page__overlay"></div>
      </div>
    </ul>
  </nav>
</header>

<main>
  
  <section>
    <h1>Simply Navigation</h1>
  
  <h4>Lightweight simple navigation built with flexbox and vanilla JavaScript</h4>
  
  <p>This is just a placeholder for an actual page, to show off this navigation component. This navigation solution is built entirely using Flexbox and vanilla JavaScript. Below are some key takeaways.</p>
    
    <ul>
      <li>No dependencies. Built using Flexbox & vanilla JavaScript only.</li>
      <li>Fully responsive.</li>
      <li>Mobile menu closes when selecting a link, try it. Open the mobile menu and click on the 'Last Section'</li>
      <li>Easy close mobile menu is closable via entire top row and right side page overlay</li>
    </ul>
    <h3>Customizable</h3>
    <ul>
      <li>Breakpoint variable - default at 800px</li>
      <li>Sticky navigation bar available</li>
      <ul>
        <li>Toggle <button>Sticky Nav</button> Sticky Nav is <span class="sticky-on-off"><strong>Off</strong></span></li>
        <li>Note: Sticky navigation bar requires padding and/or margin on the parent or adjacent element. For example, on this page the adjacent <em>main</em> HTML element has a top margin of 6.5rem (nav height is 4.5rem) </li>
      </ul>
    </ul>
    <h3>Another heading</h3>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos, iure dolorem consequuntur tenetur quasi assumenda voluptas est quae doloremque praesentium error, vel itaque pariatur dolores.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A natus deserunt quaerat assumenda explicabo! Explicabo placeat autem quod dolore! Ab molestias aliquam alias aut dolores quibusdam tempora qui velit rem dolorum, iusto deserunt architecto soluta aperiam voluptas perspiciatis excepturi saepe, et optio non. Sapiente, tenetur!</p>
    <h3 id="last-section">Last heading</h3>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Distinctio sint doloribus eveniet voluptate molestias. Modi dicta expedita minima iusto ex eligendi, neque, ratione deleniti recusandae consectetur sunt! Id facere, autem consequuntur placeat minima odio ipsum nihil vel? Iusto dolorem aliquam adipisci aliquid magnam veniam, et nesciunt expedita placeat error praesentium?</p>
  </section>
  
</main>
              
            
!

CSS

              
                // nav breakpoint variable
$breakpoint: 800px

//------- GENERIC RESET & STYLING ---------//
//------- Below is the Nav section --------//
// font stack
$font-sans: -apple-system, BlinkMacSystemFont, 'Roboto', 'Segoe UI', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans','Helvetica Neue', Arial, sans-serif

// background colors & a few shades of grays
$darkest: #1d1d1d
$darker: lighten($darkest, 5%)
$dark: lighten($darkest, 15%)
$darkish: #707875
$gray: #CACFCC

// text & accent colors
$text-color: transparentize(#F4F8FB, 0.25)
$text-color-nop: #F4F8FB
$link-color: #F0DB4F //yellow
$link-color-hover: darken($link-color, 15%)

// a simple reset that's probably not simple enough
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, section, summary, time, mark, audio, video, .row
  margin: 0
  padding: 0
  border: 0
  vertical-align: baseline
article, footer, header, nav, section 
  display: block
*, *:before, *:after
  box-sizing: border-box
  -moz-box-sizing: border-box
  -webkit-box-sizing: border-box
html
  width: 100%
  height: 100%
body 
  background-color: $darkest
  margin: 0 auto
  overflow-x: hidden
  font-size: 1rem
  font-feature-settings: kern
  -ms-font-feature-settings: kern
  -o-font-feature-settings: kern
  font-kerning: normal
  text-rendering: optimizeLegibility
  -webkit-font-smoothing: antialiased
  -osx-font-smoothing: grayscale
  -webkit-text-size-adjust: 100%
  scroll-behavior: smooth
html, body
  min-width: 320px
  font-size: 17px
body, input, select, textarea 
  font-family: $font-sans
  color: $text-color
  font-weight: 400
  line-height: 1.5
a, a:visited
  -moz-transition: color 0.2s ease-in-out, border-style 0.2s ease-in-out
  -webkit-transition: color 0.2s ease-in-out, border-color 0.2s ease-in-out
  -ms-transition: color 0.2s ease-in-out, border-style 0.2s ease-in-out
  transition: color 0.2s ease-in-out, border-style 0.2s ease-in-out
  color: $link-color
  text-decoration: none
  outline: none
  &:hover
    color: $link-color-hover
    text-decoration: none
strong, b 
  color: $text-color-nop
  font-weight: 600
em
  font-style: italic
p
  margin-top: 1rem
  margin-bottom: 1rem
  color: $text-color
  max-width: 40rem
  &:first-of-type
    margin-top: 0
h1, h2, h3, h4, h5, h6
  color: $text-color
  font-family: $font-sans
  font-weight: 700
  margin-left: auto
  margin-right: auto
h1
  font-size: 2rem
  margin-top: 2rem
  color: $text-color-nop
h2
  font-size: 1.6rem
  margin-top: 1.35rem
  margin-bottom: 1.35rem
  letter-spacing: 0.1px
h3
  font-size: 1.3rem
  margin-top: 1rem
  margin-bottom: 1rem
h4, h5, h6
  font-size: 1.1rem
  margin-bottom: 1rem
  font-weight: 500
  
ul
  margin: 0 0 1rem 0
  padding-left: 0.75rem
  li
    padding-left: 0.25rem
    margin-bottom: 0.25rem
    
button
  background: $link-color
  color: $darker
  border: 0
  border-radius: 3px
  font-size: 1rem
  margin: 0 0.15rem
  padding: 0.25rem 0.5rem
  cursor: pointer
  &:hover
    background: darken($link-color, 10%)
  
  
//////////////////////////////
// Finally, navigation styling!
//////////////////////////////
.nav-wrapper
  //bkg color is optional
  background-color: $dark
  //if you want a fixed header simply change below value to 'fixed' or apply 'sticky-nav' class
  position: absolute
  top: 0
  left: 0
  right: 0
  height: 4.5rem
  width: 100%
  margin: 0 auto
  z-index: 95
  padding: 0
  display: block
  backface-visibility: hidden
  transform-style: preserve-3d
  -webkit-backface-visibility: hidden
  -webkit-transform-style: preserve-3d
  transition: all 0.2s ease-in-out
  -webkit-transition: all 0.2s ease-in-out
  &.sticky-nav
    position: fixed

.nav
  max-width: 80rem
  width: 100%
  margin: 0 auto
  padding: 0
  display: flex
  justify-content: center

.nav__list
  background-color: transparent
  list-style: none
  margin: 0
  padding: 0
  display: block
  position: fixed
  top: -0.25rem
  bottom: 0
  left: 0
  width: 0
  min-height: 102vh
  overflow-y: scroll
  overflow-x: hidden
  overflow: hidden
  -webkit-overflow-scrolling: touch
  z-index: 99
  transition: all 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28)
  backface-visibility: hidden
  transform-style: preserve-3d
  -webkit-backface-visibility: hidden
  -webkit-transform-style: preserve-3d
  & li
    display: flex
    padding: 0
    border-bottom: 1px solid transparentize($gray, 0.5)
    &:first-child
      margin-top: 1rem
    &:last-child
      border-bottom: 0
  & .nav__item
    border-color: transparent
    padding: 0.75rem 1rem 0.5rem 1rem
    flex-basis: 100%
    display: block
    background: transparent
    font-size: 1.5rem
    padding-left: 1.5rem
    color: $text-color
    transition: all 0.3s ease-in-out
    &:hover, &.active
      color: $link-color
.nav__logo
  z-index: 90
  border-bottom: 0
  padding: 0.5rem
  backface-visibility: hidden
  transform-style: preserve-3d
  -webkit-backface-visibility: hidden
  -webkit-transform-style: preserve-3d
  position: absolute
  right: 1rem
.logo
  z-index: 92
  max-height: 25vh
  max-width: 100%
  backface-visibility: hidden
  transform-style: preserve-3d
  -webkit-backface-visibility: hidden
  -webkit-transform-style: preserve-3d
  transition: max-height 0.2s ease-in-out
  -webkit-transition: max-height 0.2s ease-in-out
  &.logo-small
    z-index: 99
    max-height: 3.5rem
    backface-visibility: hidden
    transform-style: preserve-3d
    -webkit-backface-visibility: hidden
    -webkit-transform-style: preserve-3d
    transition: max-height 0.2s ease-in-out
    -webkit-transition: max-height 0.2s ease-in-out
.page__overlay
  width: 40%
  height: 100%
  background: transparentize($dark, 0.35)
  position: absolute
  right: 0
  top: 0
  cursor: pointer
.nav__list-left
  background: $darkest
  width: 60%
  height: 100%
  position: relative
.nav__list-right
  width: 40%
#sideNav.open
  width: 100%

.toggleNav, .toggleNav:focus, .toggleNav:active
  display: block
  z-index: 91
  color: white
  padding: 1rem
  font-size: 1.5rem
  cursor: pointer
  left: 0.5rem
  position: absolute
  transition: all 0.3s
  -webkit-transition: all 0.3s
.svg-hamburger, .svg-close
  width: 1.25rem
  height: 1.25rem

.closeBtn, .closeBtn:visited, .closeBtn:active, .closeBtn:focus
  cursor: pointer
  font-size: 1.75rem
  font-weight: 800
  display: flex
  background: transparent
  border-bottom: 0
  padding: 1.25rem 1rem 1rem 1.5rem
  margin: 0
  text-align: left
  color: $dark
  transition: all 0.3s
  -webkit-transition: all 0.3s
  & span
    font-size: 1rem
    padding-left: 0.25rem
    &:hover
      color: $text-color
  .svg-close
    margin-top: 0.75rem
  .svg-close-path
    &:hover
      fill: $link-color
  &:hover
    color: $text-color

@media all and (min-width: $breakpoint)
  .toggleNav
    display: none
  .closeBtn
    display: none
  .nav__logo
    margin-left: 1rem
    position: relative
    right: unset
  .nav__list
    margin-top: 0.5rem
    position: relative
    width: 100%
    min-height: initial
    background: transparent
    z-index: 1
    overflow: hidden
    & li
      padding: 1.25rem 0
      margin-left: 1.5rem
      border-bottom-color: transparent
      justify-content: flex-start
    & .nav__item
      border-bottom: 2px solid transparent
      display: block
      flex-basis: unset
      background: transparent
      padding: 0
      font-size: 1rem
      outline: 0
      transition: all 0.2s ease-in-out
  .nav__list-left, .nav__list-right
    width: unset
    height: unset
    overflow: hidden
  .nav__list-left
    border-top: 0
    background: transparent
    display: flex
    align-items: center
  .nav__list-right
    display: none
    z-index: -1
    
//--------- END OF NAV style -------//
//--------- styling for rest of page -------//
main
  margin: 6.5rem auto 0 auto
  section
    padding: 1rem
    max-width: 60rem
    margin: 0 auto
              
            
!

JS

              
                // This anonymous function can be inserted anywhere
// (eg. within a <script> tag or anywhere in an existing .js file or its own file)
(navDuty => {   
    const sideNav = document.getElementById('sideNav');
    const closeNavBtn = document.querySelector('.closeBtn');
    const toggleNavBtn = document.querySelector('.toggleNav');
    const pageOverlay = document.querySelector('.page__overlay');

    // Nav listeners
    closeNavBtn.addEventListener('click', toggleNav);
    toggleNavBtn.addEventListener('click', toggleNav);
    pageOverlay.addEventListener('click', toggleNav);
    // Nav funtion
    function toggleNav() {
      sideNav.classList.toggle('open');
    };

    // (on mobile) close nav menu when link is clicked
    // this is useful on mobile when clicking an anchor tag on the current page (eg. index.html#last-section)
    let navItems = document.querySelectorAll(".nav__item");                     
    for (var i = 0; i < navItems.length; i++) {
      navItems[i].addEventListener('click', function (event) {
        toggleNav();
      });
    }
    //navItems.forEach( i => i.addEventListener('click', toggleNav()) );
})();


//non related
(stickyNav => {
  const button = document.querySelector('button');
  const onOffHTML = document.querySelector('.sticky-on-off');
  const on = '<strong>On</strong>';
  const off = '<strong>Off</strong>';
  const navWrapper = document.querySelector('.nav-wrapper');
  
  button.addEventListener('click', toggleStickyNav => {
    navWrapper.classList.toggle('sticky-nav');
    (navWrapper.classList.contains('sticky-nav') ? onOffHTML.innerHTML = on : onOffHTML.innerHTML = off);
  });

})();
              
            
!
999px

Console