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

              
                <body>

	<div class="container">

		<!-- Static navbar -->
		<nav class="navbar navbar-default">
			<div class="container-fluid">
				<div class="navbar-header">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
						<span class="sr-only">Toggle navigation</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					<a class="navbar-brand" href="https://www.systembyran.se" target="_blank">Business</a>
				</div>


				<div id="navbar" class="navbar-collapse collapse">
					<ul class="nav navbar-nav navbar-right">
						<li class=""><a href="#">Home <span class="sr-only">(current)</span></a></li>
						<li class="hideable"><a href="#">Menu item</a></li>
						<li class="hideable"><a href="#">Menu Item 2</a></li>
						<li class="hideable"><a href="#">Menu item 3</a></li>
						<li class="hideable"><a href="#">Menu item 4</a></li>
						<li class="active hideable"><a href="#">Menu item 5</a></li>
						<li class="hideable"><a href="#">Menu item 6</a></li>
						
						<li id="nav-more" class="dropdown hidden"><!-- the 'more' dropdown item, originally hidden -->
							<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">MORE <span class="caret"></span></a>
							<ul class="dropdown-menu">
							</ul>
						</li>
						
						<li><a href="#"><i class="glyphicon glyphicon-globe"></i></a></li>
					</ul>
				</div>
				<!--/.nav-collapse -->
			</div>
			<!--/.container-fluid -->
		</nav>

		<div class="jumbotron">
			<h1>Navbar 'more' example</h1>
			<p>Hide items that can no longer fit!</p>
      <ul>
        <li>Items that can not fit are moved to a new dropdown.</li>
        <li>Items should be returned to their original place in the navbar when space is once again available.</li>
        <li>Items can be either 'hideable' or static.</li>
        <li>Updated to make active item never hide. Duh!</li>
      </ul>
      <i>The navbar breakpoint needs to be changed for different layouts (and is not in sync for this pen)!</i>
		</div>

	</div>
	<!-- /container -->
</body>
              
            
!

CSS

              
                /** 
 * These are only for nav-colors, not needed at all for the functionality
 */
.navbar-default {
  background-color: #e82525;
  border-color: #ee5f5f;
}
.navbar-default .navbar-brand {
  color: #ffffff;
}
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-brand:focus {
  color: #560000;
}
.navbar-default .navbar-text {
  color: #ffffff;
}
.navbar-default .navbar-nav > li > a {
  color: #ffffff;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
  color: #560000;
}
.navbar-default .navbar-nav > li > .dropdown-menu {
  background-color: #e82525;
}
.navbar-default .navbar-nav > li > .dropdown-menu > li > a {
  color: #ffffff;
}
.navbar-default .navbar-nav > li > .dropdown-menu > li > a:hover,
.navbar-default .navbar-nav > li > .dropdown-menu > li > a:focus {
  color: #560000;
  background-color: #ee5f5f;
}
.navbar-default .navbar-nav > li > .dropdown-menu > li.divider {
  background-color: #ee5f5f;
}
.navbar-default .navbar-nav .open .dropdown-menu > .active > a,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
  color: #560000;
  background-color: #ee5f5f;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
  color: #560000;
  background-color: #ee5f5f;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
  color: #560000;
  background-color: #ee5f5f;
}
.navbar-default .navbar-toggle {
  border-color: #ee5f5f;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
  background-color: #ee5f5f;
}
.navbar-default .navbar-toggle .icon-bar {
  background-color: #ffffff;
}
.navbar-default .navbar-collapse,
.navbar-default .navbar-form {
  border-color: #ffffff;
}
.navbar-default .navbar-link {
  color: #ffffff;
}
.navbar-default .navbar-link:hover {
  color: #560000;
}

@media (max-width: 767px) {
  .navbar-default .navbar-nav .open .dropdown-menu > li > a {
    color: #ffffff;
  }
  .navbar-default .navbar-nav .open .dropdown-menu > li > a:hover,
  .navbar-default .navbar-nav .open .dropdown-menu > li > a:focus {
    color: #560000;
  }
  .navbar-default .navbar-nav .open .dropdown-menu > .active > a,
  .navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
  .navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
    color: #560000;
    background-color: #ee5f5f;
  }
}
              
            
!

JS

              
                var $navbar = $('#navbar');                   // Navbar to go trough!
var $more   = $('#nav-more');                 // More More item to show/hide
var $v_wrap = $('#navbar .nav');              // Visible wrapper
var $h_wrap = $('#nav-more .dropdown-menu');  // Hidden wrapper
var breaks  = [];                             // Breakpoints
var pop_all_breakpoint = 767;                 // *** modify as needed. ***

/**
 * Return child to it's original place in the nav-wrapper
 */
function returnChild( $child, $dest_wrapper ) {
  var cplace = $child.attr('data-navorder'),
      inserted = false;

  // Find place for the child... insert if found...
  $dest_wrapper.children().each( function(idx, obj){
    if ( idx == cplace ) {
      $child.insertBefore(this);
      inserted = true;
    }
  });

  // ...if we didn't find a place to insert the childe, insert it last.
  if ( !inserted ) {
    $child.appendTo( $dest_wrapper );
  }
}

/**
 * Check navbar and handle more/show/hide.
 */
function updateNav() {

  // If collapsed bootstrap nav, return all items to default places and hide 'more' dropdown.
  if ( $(window).width() < pop_all_breakpoint ) {
    while ( breaks.length ) {
      returnChild( $h_wrap.children().first(), $v_wrap );
      breaks.pop();
    }

    // Hide the 'more' dropdown
    $more.addClass('hidden');
    return; // Don't do anything else!
  }

  // Set/save order of menu-items (needed to keep their place among static items). Only run once!
  if ( $v_wrap.attr('data-navsetup') != 'done' ) {
    $v_wrap.children().each( function(idx, obj){
      if ( $(this).hasClass('hideable') )
        $(this).attr('data-navorder', idx);
    });
    $v_wrap.attr('data-navsetup', 'done');
  }

  // Calculate available space ( -30 to make sure )
  var availableSpace = $navbar.width() - 30 - $('.navbar-header').width();
  var changes = 0; // Could be true/false as well..

  // The visible list is overflowing the nav & we have stuff we CAN hide
  if ( availableSpace < $v_wrap.width() && $v_wrap.children('.hideable:not(.active)') ) {

    // Record the width of the list
    breaks.push( $v_wrap.width() );
    changes++;

    // Move item to the hidden list
    $v_wrap.children('.hideable:not(.active)').last().prependTo( $h_wrap );

    // Show the dropdown btn
    if ($more.hasClass('hidden')) {
      $more.removeClass('hidden');
      $h_wrap.removeClass('hidden');
    }
  }
  else { // The visible list is not overflowing

    // Is there space for another item in the nav?
    if (availableSpace > breaks[breaks.length - 1]) {

      // Move the item to the visible list
      returnChild( $h_wrap.children().first(), $v_wrap );
      breaks.pop();
      changes++;
    }

    // Hide the dropdown btn if hidden list is empty
    if ( breaks.length <= 0 ) {
      $more.addClass('hidden');
      $h_wrap.addClass('hidden');
    }
  }

  // Recur if changes were made
  if ( changes ) {
    updateNav();
  }

}

// Window resize listener + trigger
$(window).resize(function() {
  updateNav();
}).trigger('resize');
              
            
!
999px

Console