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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <ul class="site-nav" id="accessibleNav">
  <li>
    <a href="#">Link 1</a>
  </li>
  <li>
    <a href="#">Link 2</a>
  </li>
  <li class="site-nav--has-dropdown" aria-haspopup="true">
    <a href="#">Link 3 &#8595;</a>
    <ul class="site-nav--dropdown">
      <li><a href="#">Link 3a</a></li>
      <li><a href="#">Link 3b</a></li>
      <li><a href="#">Link 3c</a></li>
    </ul>
  </li>
  <li class="site-nav--has-dropdown" aria-haspopup="true">
    <a href="#">Link 4 &#8595;</a>
    <ul class="site-nav--dropdown">
      <li><a href="#">Link 4a</a></li>
      <li><a href="#">Link 4b</a></li>
      <li><a href="#">Link 4c</a></li>
    </ul>
  </li>
  <li>
    <a href="#">Link 5</a>
  </li>
  <li>
    <a href="#">Link 6</a>
  </li>
</ul>

<div class="intro">
  <h3>
    Super accessible navigation
  </h3>
  <ul>
    <li>Keyboard friendly</li>
    <li>CSS transitions for drop downs</li>
    <li>Touch-friendly</li>
    <li>Screen reader friendly</li>
  </ul>
</div>
            
          
!

CSS

            
              html, body {
  min-height: 100%;
}

body {
  padding: 100px 0;
}

.intro {
  padding: 20px 20px 100px;
}

.site-nav {
  display: block;
  margin: 0 auto;
  list-style: none;
  background: #333;
  text-align: center;
  font: {
    family: 'Open Sans', sans-serif;
    size: 16px;
    text-transform: uppercase;
    cursor: default;
  }
  
  ul, li {
    padding: 0;
    margin: 0;
  }

  li {
    position: relative;
    display: inline-block;
  }

  a {
    display: block;
    text-decoration: none;
    color: #fff;
    padding: 10px;
    
    &:hover,
    &:focus {
    	background-color: darken(#333, 5%);  
    }
  }
}
    
.site-nav--dropdown {
  display: block;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 5;
  background-color: #333;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0,-3px,0);
  transition: transform 400ms ease-out, opacity 150ms ease-out 100ms, visibility linear 200ms;
    
  a {
    text-transform: none;
    text-align: left;
    padding: 10px 50px 10px 10px;
    white-space: nowrap;
  }

  .no-touch .site-nav--has-dropdown:hover &,
  .site-nav--has-dropdown.nav-hover &,
  .nav-focus + & {
    opacity: 1;
    visibility: visible;
    transform: translate3d(0,0,0);
    transition: transform 120ms ease-in, opacity 0s ease-out, visibility linear;
  }
}
            
          
!

JS

            
              window.timber = window.timber || {};

$(function() {
  timber.cache = {
    // General
    $html: $('html'),
    $body: $('body'),

    // Navigation
    $navigation: $('#accessibleNav')
  };
});

timber.accessibleNav = function () {
  var $nav = timber.cache.$navigation,
      $allLinks = $nav.find('a'),
      $topLevel = $nav.children('li').find('a'),
      $parents = $nav.find('.site-nav--has-dropdown'),
      $subMenuLinks = $nav.find('.site-nav--dropdown').find('a'),
      activeClass = 'nav-hover',
      focusClass = 'nav-focus';
  
  if ('ontouchstart' in window) {
    timber.cache.$html.removeClass('no-touch').addClass('supports-touch');
  }

  // Mouseenter
  $parents.on('mouseenter touchstart', function(evt) {
    var $el = $(this);

    if (!$el.hasClass(activeClass)) {
      evt.preventDefault();
    }

    showDropdown($el);
  });

  $parents.on('mouseleave', function() {
    hideDropdown($(this));
  });

  $subMenuLinks.on('touchstart', function(evt) {
    // Prevent touchstart on body from firing instead of link
    evt.stopImmediatePropagation();
  });

  $allLinks.focus(function() {
    handleFocus($(this));
  });

  $allLinks.blur(function() {
    removeFocus($topLevel);
  });

  // accessibleNav private methods
  function handleFocus ($el) {
    var $subMenu = $el.next('ul');
        hasSubMenu = $subMenu.hasClass('site-nav--dropdown') ? true : false,
        isSubItem = $('.site-nav--dropdown').has($el).length,
        $newFocus = null;

    // Add focus class for top level items, or keep menu shown
    if ( !isSubItem ) {
      removeFocus($topLevel);
      addFocus($el);
    } else {
      $newFocus = $el.closest('.site-nav--has-dropdown').find('a');
      addFocus($newFocus);
    }
  }

  function showDropdown ($el) {
    $el.addClass(activeClass);

    setTimeout(function() {
      timber.cache.$body.on('touchstart', function() {
        hideDropdown($el);
      });
    }, 250);
  }

  function hideDropdown ($el) {
    $el.removeClass(activeClass);
    timber.cache.$body.off('touchstart');
  }

  function addFocus ($el) {
    $el.addClass(focusClass);
  }

  function removeFocus ($el) {
    $el.removeClass(focusClass);
  }
}

// Initialize Timber's JS on docready
$(function() {
  window.timber.accessibleNav();
});
            
          
!
999px

Console