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.

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

              
                
<nav>
  <ul>
    <li class="active"><a href="">First</a></li>
    <li><a href="">Second</a></li>
    <li><a href="">Third</a></li>
  </ul>
</nav>
              
            
!

CSS

              
                *
  box-sizing: border-box

body
  background: #1A1E23
  font-family: 'Lato', sans-serif
  -webkit-font-smoothing: antialiased

nav
  position: relative
  padding-bottom: 12px
  .line
    height: 2px
    position: absolute
    bottom: 0
    margin: 10px 0 0 0
    background: #FF1847
  ul
    padding: 0
    margin: 0
    list-style: none
    display: flex
    li
      margin: 0 40px 0 0
      opacity: .4
      transition: all 0.4s ease
      &:hover
        opacity: .7
      &.active
        opacity: 1
      &:last-child
        margin-right: 0
      a
        text-decoration: none
        color: #fff
        text-transform: uppercase
        display: block
        font-weight: 600
        letter-spacing: .2em
        font-size: 14px
        
//Center
body
  display: flex
  justify-content: center
  align-items: center
  min-height: 100vh
              
            
!

JS

              
                var nav = $('nav');
var line = $('<div />').addClass('line');

line.appendTo(nav);

var active = nav.find('.active');
var pos = 0;
var wid = 0;

if(active.length) {
  pos = active.position().left;
  wid = active.width();
  line.css({
    left: pos,
    width: wid
  });
}

nav.find('ul li a').click(function(e) {
  e.preventDefault();
  if(!$(this).parent().hasClass('active') && !nav.hasClass('animate')) {
    
    nav.addClass('animate');

    var _this = $(this);

    nav.find('ul li').removeClass('active');

    var position = _this.parent().position();
    var width = _this.parent().width();

    if(position.left >= pos) {
      line.animate({
        width: ((position.left - pos) + width)
      }, 300, function() {
        line.animate({
          width: width,
          left: position.left
        }, 150, function() {
          nav.removeClass('animate');
        });
        _this.parent().addClass('active');
      });
    } else {
      line.animate({
        left: position.left,
        width: ((pos - position.left) + wid)
      }, 300, function() {
        line.animate({
          width: width
        }, 150, function() {
          nav.removeClass('animate');
        });
        _this.parent().addClass('active');
      });
    }

    pos = position.left;
    wid = width;
  }
});
              
            
!
999px

Console