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 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

              
                nav.js-nav(role='navigation', aria-label='Primary Navigation')
  - var n = 0
  ul.js-main-nav
    while n < 20
      li.js-nav-item
        a(href='') Item #{n++}
    li.js-nav-item
      span Hello
      ul
        li
          a(href='') hello
    li.is-hidden.js-more
      span More
      ul.js-more-menu
nav.nav--small.js-nav(role='navigation', aria-label='Primary Navigation')
 - var n = 0
 ul.js-main-nav
   while n < 20
     li.js-nav-item
       a(href='') Item #{n++}
   li.js-nav-item
     span Hello
     ul
       li
         a(href='') hello
   li.is-hidden.js-more
     span More
     ul.js-more-menu
              
            
!

CSS

              
                nav
  position relative
  max-width 1280px
  width 100%
  margin 0 auto  
  background-color grey
  
  ul
    width 100%
    padding 0
    margin 0
    white-space nowrap
  
  li
    position relative
    display inline-block
    
    a
    span
      display block
      padding 0.5em 2em
      color white
    
    &:hover
      background-color blue
      
      > ul
        display block
      
     > ul
         display none
         position absolute
         top 100%
         left 0
        
       li
         display block
         background-color red
  
.is-hidden
  display none

.nav--small
  max-width 900px
              
            
!

JS

              
                var $window = $(window),
  $allNavs = $('.js-main-nav')

function initCalc() {
  $allNavs.children('.js-nav-item').each(function() {
    var $this = $(this)
    $this.attr('data-width', $this.outerWidth(true))
  })
}

function calcWidth($nav) {
  var navwidth = 0,
    $moreMenu = $nav.find('.js-more'),
    $moreDrop = $nav.find('.js-more-menu'),
    morewidth = $moreMenu.outerWidth(true)

  $nav.children('.js-nav-item').each(function() {
    navwidth += $(this).data('width')
  })

  var availablespace = $nav.width() - morewidth

  if (navwidth > availablespace) {
    var lastItem = $nav.children('.js-nav-item').last()
    lastItem.prependTo($moreDrop)
    calcWidth($nav)
  } else {
    var firstMoreElement = $moreDrop.find('li').first()
    if (navwidth + firstMoreElement.data('width') < availablespace) {
      firstMoreElement.insertBefore($moreMenu)
    }
  }

  if ($moreDrop.children('li').length > 0) {
    $moreMenu.removeClass('is-hidden')
  } else {
    $moreMenu.addClass('is-hidden')
  }
}

$(document).ready(function() {
  initCalc()
  $allNavs.each(function() {
    calcWidth($(this))
  })
})

$window.on('resize load', function() {
  $allNavs.each(function() {
    calcWidth($(this))
  })
})
              
            
!
999px

Console