Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!--
  Drop down menu example

  Note: this demo is not 
  currently setup for any
  specific responsive behaviors.
-->

<div class="page">

  <header role="banner" aria-label="Primary">

    <nav role="navigation" aria-label="Primary" id="nav" class="nav">

      <ul id="nav_inner" class="nav__list">
        <li class="has-drop">
          <a href="#!">
            Drop Down
          </a>

          <ul class="nav__list__drop">
            <li>
              <a href="#!">
                Item 1
              </a>
            </li>
            <li>
              <a href="#!">
                Item 2
              </a>
            </li>
          </ul>
        </li>

        <li>
          <a href="#!">
            Normal
          </a>
        </li>

        <li class="has-drop">
          <a href="#!">
            Drop Down 2
          </a>

          <ul class="nav__list__drop">
            <li>
              <a href="#!">
                Item 1 has a long name
              </a>
            </li>
            <li>
              <a href="#!">
                Item 2
              </a>
            </li>
          </ul>
        </li>
      </ul>

    </nav>
  </header>

</div>
            
          
!
            
              /*
  General cleanup
*/

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

html,
body {
  font-family: helvetica, arial, sans-serif;
  font-size: 18px;
  margin: 0;
  padding: 0;
}

nav ul,
nav ol {
  list-style: none;
  padding: 0;
  margin: 0;
}


.sr-only {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px);
  font-size: 1px;
}


/*
  Demo
*/
.show-nav {
  position: fixed;
  top: 0;
  right: 0;
}

.nav__list {
  background: #fafafa;
  border-bottom: 1px solid #444;
  text-align: center;
  position: relative;
  z-index: 2;
}

.nav__list > li {
  display: inline-block;
}

.nav__list a {
  display: block;
  padding: 20px;
  position: relative;
  z-index: 2;
}

.nav__list a:hover,
.nav__list a:focus {
  background: #222;
  color: #fff;
}

.has-drop {
  position: relative;
}


.nav__list__drop {
  left: 0;
  margin: 0;
  position: absolute;
  text-align: left;
  top: 100%;
  opacity: 0;
  transform: translateY(-20px);
  height: 1px;
  transition: transform .2s ease-in-out,
              opacity .1s ease-out;
  overflow: hidden;
  z-index: 1;
}

.nav__list__drop {
  background: #fafafa;
  border: 1px solid #444;
  border-top: 0;
  min-width: 100%;
}

.nav__list__drop a {
  padding: 12px 20px;
  white-space: nowrap;
}

.nav__list a:focus + .nav__list__drop,
.has-drop:hover .nav__list__drop,
.nav__list__drop.has-focus {
  opacity: 1;
  transform: translateY(0px);
  height: auto;
  z-index: 1;
}

.no-js .nav__list__drop {
  display: none;
}

.no-js .has-drop:hover .nav__list__drop {
  display: block;
}


            
          
!
            
              (function ( w, doc ) {

  // Enable strict mode
  "use strict";

  // Local object for method references
  var DropNav = {};

  // Namespace it up yo
  DropNav.ns = "Drop Navigation";

  // the main event...err..function
  DropNav.init = function () {

    var hasDrop = doc.querySelectorAll('.has-drop'),
      hasDropLinks = doc.querySelectorAll('.nav__list__drop a'),
      hasDropCount = hasDrop.length,
      hasDropLinksCount = hasDropLinks.length,
      i;

    if ( hasDropCount > 0 ) {

      for ( i = 0; i < hasDropCount; i++ ) { // i++  =  i = i + 1 

        var drop = hasDrop[i],
          firstDropLink = drop.querySelectorAll('.nav__list__drop a')[0];

        firstDropLink.innerHTML = ' <span class="sr-only">Sub menu, </span>' + firstDropLink.innerHTML; //*

      } //for

      for ( i = 0; i < hasDropLinksCount; i++ ) {

        var dropLinks = hasDropLinks[i];

        dropLinks.addEventListener('focus', function ( e ) {
          this.parentNode.parentNode.classList.add('has-focus');
        });

        dropLinks.addEventListener('blur', function ( e ) {
          this.parentNode.parentNode.classList.remove('has-focus');
        });

      } //for

    } //if

  }; //init

  DropNav.init();

})( this, this.document );

/* 
  Created Aug 22, 2016
  
  Revised Aug 23, 2016
  * https://codepen.io/svinkle
  Switched from aria label to adding visually hidden "sub menu" text to the first item in the drop down, to ensure that all screen readers would accurately announce "sub menu"
  
  Fixed z-index of primary link & drop menu to ensure that the primary link always appeared on top of the drop menu
  
  Reveal drop menu on focus of primary link, to make it more apparent that a sub menu exists. suppose this could have been done with a down arrow on the primary link. but nope :) 
*/
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console