123

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.

            
              <ul class="PrimaryNav with-indicator">
    <li class="Nav-item"><a href="#">Home</a></li>
    <li class="Nav-item"><a href="#">About</a></li>
    <li class="Nav-item is-active"><a href="#">Writing</a></li>
    <li class="Nav-item"><a href="#">Clients</a></li>
    <li class="Nav-item"><a href="https://twitter.com/jnowland">Contact</a></li>
  </ul>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Open+Sans:800);

// How many menu items do we have?
$menu-items: 5;

// Colours
$background-color: #121212;
$indicator-color: #e82d00;

// Transition Speed
$transition-speed: 1.3s;

// Dynamic Variables
$width: (100/$menu-items) * 1%; // makes each item the right size
$menu-items-loop-offset: $menu-items - 1; // the number of items in the menu


// ======================================================
// Step 1 - Making a Fixed Width Navigation
// ======================================================

.PrimaryNav {
  @extend %cf; // clear the floats
  list-style: none;
  margin: 50px auto;
  max-width: 720px; // As all measurements are using % this could be a flexible value.
  padding: 0;
  width: 100%;
}

.Nav-item {
  background: #fff;
  display: block;
  float: left;
  margin: 0;
  padding: 0;
  width: $width; //dynamic width
  text-align: center;

  &:first-child {
    border-radius: 3px 0 0 3px;
  }

  &:last-child {
    border-radius: 0 3px 3px 0;
  }

  &.is-active a {
    color: $indicator-color;
  }

  a {
    color: $background-color;
    display: block;
    padding-top: 20px;
    padding-bottom: 20px;
    text-decoration: none;

    &:hover {
      color: $indicator-color;
    }
  }
}


// ======================================================
// Step 2 - Making the pseudo indicator
// ======================================================

.with-indicator {
  position: relative;// the menu is "relative" to the absolute position last-child pseudo elements.
  z-index: 0;

  .Nav-item {
    // ======================================================
    // Step 2.1 - Making the indicator with the pseudo element.
    // ======================================================
    &:last-child {
      &:before, &:after {
        content: '';
        display: block;
        position: absolute;
        pointer-events: none;
        transition: left #{$transition-speed} ease;
      }
      // Making the top CSS Triangle - learn more: https://css-tricks.com/animation-css-triangles-work/
      &:before {
        border: 6px solid transparent;
        border-top-color: $indicator-color;
        width: 0;
        height: 0;
        top: 0;
        left: ($width/2);
        margin-left: -3px;
      }
      &:after {
        background: $indicator-color;
        top: -6px;
        bottom: -6px;
        left: 0;
        width: $width;
        z-index: -1;
      }


    }

  }

  @for $i from 1 through $menu-items-loop-offset {
    // when the Nav item "is active", make the indicator line up with the navigation item.
    .Nav-item:nth-child(#{$i}).is-active ~ .Nav-item:last-child:after {
      left:($width*$i)-$width;
    }
    .Nav-item:nth-child(#{$i}).is-active ~ .Nav-item:last-child:before
    {
      left:($width*$i)+($width/2)-$width; // this ensures the triangle lines up to the menu.
    }
}

// ======================================================
// Step 3 - Making it move
// ======================================================

    // This could be in the same loop as the above but for the tutorial steps it's not
    @for $i from 1 through $menu-items-loop-offset {
    // We have to use !important to make the hovers overide if the last:child is the active or hovered
    .Nav-item:nth-child(#{$i}):hover ~ .Nav-item:last-child:after {
      left:($width*$i)-$width !important;
    }

    .Nav-item:nth-child(#{$i}):hover ~ .Nav-item:last-child:before{
      left:($width*$i)+($width/2)-$width !important;
    }
      
  }
    
    // this could be nested in the original .Nav-item
    .Nav-item {
        &:last-child {
          // make sure the last-child talks to itself
          &:hover, &.is-active {
            &:before {
             // we have to use important because the sibling selctor is more specific.
              left: (100%-$width)+($width/2) !important;
            }
            &:after{
              left: 100%-$width !important;
            }
          }        
        }
    }

}


// ======================================================
// The usual Global resets
// ======================================================

*, *:before, *:after {
  box-sizing: border-box; // learn more: https://css-tricks.com/box-sizing/
}

// Extending the https://css-tricks.com/micro-clearfix/
%cf:before,
%cf:after {
    content: " ";
    display: table;
}
%cf:after {
    clear: both;
}

// Presentation Styling

html {
  background-color: $background-color;
  font-family: 'Open Sans', sans-serif;
  font-weight: 800;
}

.toggle {
    color: #fff;
    font-family: sans-serif;
    text-align: center;
}

            
          
!
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