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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!-- Default WordPress-generated structure
Extraneousclasses have been removed for simplicity -->
<nav class="site-navigation" role="navigation" aria-label="Main Navigation">
  <ul class="nav">
    <li class="menu-item active"><a href="#">Home</a></li>
    <li class="menu-item-has-children"><a href="#fallback-page">About</a>
      <ul class="sub-menu">
        <li><a href="#">People</a></li>
        <li><a href="#">Company</a></li>
        <li><a href="#">Website</a></li>
      </ul>
    </li>
    <li class="menu-item menu-item-has-children"><a href="#fallback-page">Work</a>
      <ul class="sub-menu">
        <li><a href="#2017">2017</a></li>
        <li><a href="#2016">2016</a></li>
        <li><a href="#2015">2015</a></li>
      </ul>
    </li>
    <li class="menu-item"><a href="#">Contact</a></li>
    <li class="menu-item"><a href="#">Blog</a></li>
  </ul>
</nav>
              
            
!

CSS

              
                //=== Reveal drop-down
.sub-menu {
  opacity: 0;
  transform: translate3d(0, -2rem, 0) scale(0.8);
  visibility: hidden;
  
  [aria-expanded=true] + & {
    opacity: 1;
    transform: none;
    visibility: visible;
  }
}

//=== Page styling, ignore

$white: #f3f1fe;
$purple: #8b5ab7;
$purple-blue: #8067fd;
$pink: #fc9bb6;
$blue: #97bcff;
$cyan: #50cba1;
$yellow: #ffbb61; // This color fails contrast requirements: there is no way to have yellow text on a white background and pass contrast requirements. But the design of this pen isn't the point and won't be of use to anyone, unless you really like the Easter aesthetic. I've had a long week. Let me have this one color.

$shadow: 0 0.25em 2em rgba($purple-blue, 0.4);
$border-color: mix($white, #d4d4db);
  
@mixin pattern-zigzag($size : 20px, $color1 : #000, $color2: #fff) {
  $deg  : 45deg;
  $change: 90;
  $deg2 : $deg + $change;
  $deg3 : $deg2 + $change;
  $deg4 : $deg3 + $change;
  
  background-color: $color2;
  background-image: 
    linear-gradient($deg2, $color1 $size/3, transparent $size/3), 
    linear-gradient($deg3, $color1 $size/3, transparent $size/3),
    linear-gradient($deg4, $color1 $size/3, transparent $size/3),
    linear-gradient($deg, $color1 $size/3, transparent $size/3);
  background-position: -$size/2 0, -$size/2 0, 0 0, 0 0;
  background-size: $size $size;
}

@mixin shape-triangle($size, $direction : top, $color : inherit) {
  $opposite: bottom;
  
  @if($direction == 'bottom') { $opposite: 'top'; }
  @if($direction == 'left') { $opposite: 'right'; }
  @if($direction == 'right') { $opposite: 'left'; }
  
  border: $size solid transparent;
  border-#{$direction}-color: $color;
  border-#{$opposite}-width: 0;
}

body { background: $white; }

.site-navigation {
  background: #fff;
  border-radius: 3px;
  box-shadow: $shadow;
  color: $purple;
  font: 700 1.375rem / 1 'Noto Sans', sans-serif;
  max-width: 996px;
  margin: 2em auto;
  text-align: center;
  
  ul, li {
    list-style: none;
    margin: 0;
    padding: 0;
  }
}

.nav {  
  > li { 
    border-bottom: 2px solid $border-color;
    position: relative; 
  }
  
  @media (min-width: 768px) {
    display: flex;
    justify-content: space-around;
    
    > li {
      border: 0;
      flex: 1 1 auto;
    
      // Don't do this to your selectors
      &:not(:last-child)::before {
        background: $border-color;
        content: '';
        display: block;
        transform: skew(-15deg);
        width: 4px;
        position: absolute;
        top: 0; bottom: 0; right: 2px;
        z-index: 10;
      }
      
    }
  }
  
  a {
    color: inherit; 
    text-decoration: none;
    transition: 0.2s;
    display: block;
    overflow: hidden;
    padding: 1.25em;
    position: relative;
    
    &::before {
      @include pattern-zigzag(0.4em, #fff, $pink);
      
      content: '';
      display: block;
      position: absolute;
      top: 50%; right: 1.25em; left: 1.25em;
      margin-right: 8px; margin-top: 0.75em;
      height: 0.4em;
      transform: translateY(3em);
      transition: 0.3s ease-out;
    }
    
    &:hover,
    &:focus {
      color: $yellow;
      
      &::before {
        transform: none;
      }
    }
    
    &:focus { outline: 2px dotted $yellow; }
    &:active { color: $cyan; }
  }  
}

// Indicator
.menu-item-has-children > a {
  &::after {
    @include shape-triangle(0.25em, top, $yellow);
    
    content: '';
    display: inline-block;
    transition: 0.2s;
    margin-top: -0.125em;
    margin-left: 0.5em;
    position: relative;
    vertical-align: middle;
  }
  
  &[aria-expanded=true]::after {
    transform: rotate(180deg);
  }
}

li.active a::after {
  @include shape-triangle(0.25em, bottom, $cyan);
  content: '';
  position: absolute;
  bottom: 0; left: 50%;
  margin-left: -0.125em;
}

.sub-menu {
  background: #fff;
  box-shadow: 0 0.25em 2em rgba(#8067fd, 0.4);
  position: absolute;
  top: 100%; left: 50%;
  transform-origin: top center;
  transition: 0.3s ease-out;
  width: 11rem;
  z-index: 2;
  
  &#{&} { margin-left: -5.5rem; }
  
  li { border: 1px solid $border-color; }
  a { transform: translate3d(0, 1em, 0); }
  
  @for $i from 1 through 5 {
    li:nth-child(#{$i}) a {
      transition-delay: $i * 0.1s;
    }
  }
  
  [aria-expanded=true] + & a {
    transform: none;
  }
}
              
            
!

JS

              
                // Using jQuery because WordPress already has it
(function($) {
  var $allMenus = $(".menu-item-has-children");
  var $allToggles = $allMenus.find('> a');
  var $allTopLinks = $(".nav > li > a");
  
  var hoverTimer, blurTimer, 
      delay = 500;

  // Reusable functions
  function openMenu($current) {
    $allToggles.attr("aria-expanded", "false");
    $current.attr("aria-expanded", "true");
  }

  function closeMenu($current) {
    $current.attr("aria-expanded", "false");
  }

  function focusSubmenu($current) {
    $current.on("transitionend", function() {
      if ($current.css("visibility") === "visible") {
        $current.find("li:first-child a").focus();
        $current.off("transitionend");
      } 
    });
  }

  // Add aria roles
  $(".menu-item.active > a").attr("aria-current", "page");
  $allToggles.attr({
    "aria-haspopup": "true",
    "aria-expanded": "false",
    "role": "button"
  });

  // Open menu on hover
  $allMenus.on("mouseenter", function(e) {
    openMenu($(this).find("[aria-expanded]"));

    clearTimeout(hoverTimer);
  });

  // Close menu after a short delay
  $allMenus.on("mouseleave", function() {
    var $element = $(this).find("[aria-expanded]");

    hoverTimer = setTimeout(function() {
      closeMenu($element);
    }, delay);
  });

  // Toggle menu on click, tap, or focus + enter/space
  $allToggles
    .on("click touchstart", function(e) {
      var $this = $(this);
      var $submenu = $this.next(".sub-menu");

      if ($this.attr("aria-expanded") === "true") closeMenu($this);
      else openMenu($this);

      focusSubmenu($submenu);

      e.preventDefault();
    })
    .on("keyup", function(e) {
      if (e.keyCode === 32) {
        openMenu($(this));
        focusSubmenu($(this).next(".sub-menu"));
      }
    });

  // Close menu when refocusing on top-level links
  $allTopLinks.on("focus", function() {
    closeMenu($allToggles);
  });

  // Close menu on esc and focus loss
  $(".site-navigation").on("keyup", function(e) {
    if (e.keyCode === 27) closeMenu($allToggles);
  });
  
  // Close menu if focus isn't inside site navigation
  $('.sub-menu').on('focusout', function(){
    // There's a delay between focusout and re-focus
    setTimeout( function() {
      var $focused = $(document.activeElement);
      if($focused.closest('.site-navigation').length === 0 ) {
        closeMenu($allToggles);
      }
    }, 1);
  });

})(jQuery);
              
            
!
999px

Console