Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- header -->
<header id="header">
	<!-- nav -->
	<nav id="main-navbar">
		<div class="container">
			<!-- navigation-header when small screen -->
			<div class="navigation-header">
				<!-- burger-icon when small screen -->
				<a href="#" class="burger-icon toggle-navbar burger-left">
					<span></span><span></span><span></span>
				</a><!-- /burger-icon -->
			</div><!-- /navigation-header -->
			<!-- navbar-nav, main-navbar -->
			<ul class="navbar navigation-nav" id="navbar">
				<li class="active"><a class="" href="#">Home</a></li>
				<li class=""><a class="" href="#">Link 1</a></li>
				<li class="dropdown">
					<a class="dropdown-toggle" href="#">Dropdown&nbsp;&nbsp;&or;</a>
					<ul>
						<li><a href="#">Dropdown link 1</a></li>
						<li><a href="#">Dropdown link 2</a></li>
					</ul>
				</li>
				<li class=""><a class="" href="#">Link 2</a></li>
				<li class=""><a class="" href="#">Another link</a></li>
			</ul><!-- /navbar-nav -->
		</div>
	</nav><!-- /nav -->
</header><!-- /header -->

<!-- section -->
<section class="container">
	
	<div class="jumbotron">
		<h1>Responsive nav</h1>
		
		<p>A simple and responsive navigation with dropdown menu.</p>
	</div>
	
</section><!-- /section -->
              
            
!

CSS

              
                /*
Name: Responsive navigation
Author: Jean LAW YIM WAN
Author URI: http://jean-lawyimwan.fr/
Copyright: 2016, Jean LAW YIM WAN
*/

/**
 * Mixins
 */
@mixin clearfix() {
  &:before,
  &:after {
	content: " "; /** 1 */
	display: table; /** 2 */
  }
  &:after {
	clear: both;
  }
}

@mixin format-font($font-size) {
  font-size: $font-size + px;
  line-height: $font-size * 1.5 + px;
  
  &:last-child {
	margin-bottom: 0;
  }
}


@function top-shadow($depth) {
  $primary-offset: nth(1.5 3 10 14 19, $depth) * 1px;
  $blur: nth(1.5 3 10 14 19, $depth) * 4px;
  $color: rgba(black, nth(.12 .16 .19 .25 .30, $depth));
  
  @return 0 $primary-offset $blur $color;
}
@function bottom-shadow($depth) {
  $primary-offset: nth(1.5 3 6 10 15, $depth) * 1px;
  $blur: nth(1 3 3 5 6, $depth) * 4px;
  $color: rgba(black, nth(.24 .23 .23 .22 .22, $depth));
  
  @return 0 $primary-offset $blur $color;
}
@mixin material-shadow($depth) {
  @if $depth < 1 or $depth > 5 {
	box-shadow: none;
  } @else {
	box-shadow: bottom-shadow($depth), top-shadow($depth);
  }
}


/**
 * Variables
 */
$colors: (
  _blue: #317bac,
  _darkBlue: darken(#317bac, 10%),
);


/**
 * Component burger-icon
 */
.burger-icon {
  text-decoration: none;
  color: #FFFFFF;
  display: block;
  cursor: pointer;
  width: 30px;
  height: 30px;
  position: absolute;
  top: 17.5px;
  
  transform: rotate(0deg);
  transition: .5s ease-in-out;
  
  > span {
	display: block;
	position: absolute;
	height: 5px;
	width: 100%;
	background: #FFFFFF;
	border-radius: 2px;
	opacity: 1;
	left: 0;
	
	transform: rotate(0deg);
	transition: .25s ease-in-out;
  }
}

.burger-right {
  right: 15px;
}

.burger-left {
  left: 15px;
}

.burger-icon > span:nth-child(1) {
  top: 0;
  -webkit-transform-origin: left center;
  -moz-transform-origin: left center;
  -o-transform-origin: left center;
  transform-origin: left center;
}

.burger-icon > span:nth-child(2) {
  top: 10px;
  -webkit-transform-origin: left center;
  -moz-transform-origin: left center;
  -o-transform-origin: left center;
  transform-origin: left center;
}

.burger-icon > span:nth-child(3) {
  top: 20px;
  -webkit-transform-origin: left center;
  -moz-transform-origin: left center;
  -o-transform-origin: left center;
  transform-origin: left center;
}

.burger-icon.open > span:nth-child(1) {
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  transform: rotate(45deg);
  top: -3px;
  left: 8px;
}

.burger-icon.open > span:nth-child(2) {
  width: 0;
  opacity: 0;
}

.burger-icon.open > span:nth-child(3) {
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  transform: rotate(-45deg);
  top: 18px;
  left: 8px;
}

/**
 * Component navbar
 */
#main-navbar {
  background: map-get($colors, _blue);
  
  .container {
	@media (max-width: 992px) {
	  width: 100%;
	  padding-left: 0;
	  padding-right: 0;
	}
  }
}

/** Base class */
.navbar {
  display: block;
  margin-bottom: 0;
  padding-left: 0; // Override default ul/ol
  list-style: none;
  @include clearfix;
  
  @media (max-width: 992px) {
	display: none;
  }
  
  > li {
	position: relative;
	display: block;
	
	> a {
	  position: relative;
	  display: block;
	  padding: 20px 15px;
	  
	  &:hover, &:focus {
		text-decoration: none;
	  }
	}
  }
}

/** Navbar open when small screen */
.navbar.open {
  display: block;
}

/** Responsive navbar */
.navbar > li {
  position: relative;
  @media (max-width: 544px) {
	width: 100%;
  }
  @media (min-width: 544px) and (max-width: 992px) {
	width: 50%;
  }
}


/** navigation-nav */
.navigation-nav {
  border: none;
  
  > li {
	float: left;
	
	> a {
	  color: #FFFFFF;
	  transition: background .2s, color .2s;
	  -webkit-transition: background .2s, color .2s;
	  
	  &:hover {
		background: map-get($colors, _darkBlue);
		color: #FFFFFF;
	  }
	}
	
	
	/** Dropdown menu */
	&.dropdown {
	  &.open { // can add &:hover if needed
		background: map-get($colors, _darkBlue);
		
		> ul {
		  display: block;
		}
	  }
	  
	  
	  > ul {
		z-index: 1000;
		display: none;
		float: left;
		min-width: 170px;
		padding: 0;
		font-size: 14px;
		text-align: left;
		list-style: none;
		background-color: map-get($colors, _blue);
		@include material-shadow(1);
		
		/** Responsive dropdown menu */
		@media (max-width: 992px) {
		  position: relative;
		  width: 100%;
		}
		@media (min-width: 992px) {
		  position: absolute;
		  top: 100%;
		  left: 0;
		}
		
		> li {
		  position: relative;
		  display: block;
		  
		  > a {
			position: relative;
			display: block;
			color: #FFFFFF;
			padding: 5px 15px;
			
			@media (max-width: 992px) {
			  padding: 20px 30px;
			}
			
			&, &:hover, &:focus {
			  text-decoration: none;
			}
			
			&:hover, &:focus {
			  background: map-get($colors, _darkBlue);
			}
		  }
		}
	  }
	}
	
	/** Active state of tab */
	&.active > a {
	  &, &:hover, &:focus {
		color: #FFFFFF;
		background: map-get($colors, _darkBlue);
	  }
	}
  }
}

/** Navigation header when tablet or smartphone */
.navigation-header {
  z-index: 110;
  display: none;
  text-transform: uppercase;
  font-weight: 700;
  @include material-shadow(1);
  background: map-get($colors, _blue);
  height: 60px;
  width: 100%;
  
  position: relative;
  
  > .navigation-brand {
	position: relative;
	display: table;
	color: #FFFFFF;
	padding: 20px 15px;
	background: red;
	
	&, &:hover, &:focus {
	  text-decoration: none;
	}
  }
  
  // show navigation-header when small screen
  @media (max-width: 992px) {
	display: block;
  }
}


/**
 * Core css
 */
html, body {
  margin: 0;
  font-family: Lato, sans-serif;
}

// position of icon
.icon-left {
  position: absolute;
  top: 0;
  left: 0;
  
  span {
	left: 15px;
  }
}

.jumbotron {
  margin-top: 30px;
}
              
            
!

JS

              
                /**
 * @name: Navbar
 * @description: Class nav for controlling the navbar
 */
var Navbar = function(container) {
	var that = this;
	
	this.dom = {};
	this.dom.container = container;
	
	/**
	 * @name: init
	 * @description: Initialize elements
	 */
	this.init = function() {
		this.dom.dropdown = {};
		this.dom.dropdown.elem = this.dom.container.find('.dropdown');
		this.dom.dropdown.toggle = this.dom.container.find('.dropdown-toggle');
		
		/** icons in header-nav */
		this.dom.toggleNavbar = this.dom.container.find('.toggle-navbar');
		
		/** navbar */
		this.dom.navbar = {};
		this.dom.navbar.all = this.dom.container.find('.navbar');
		this.dom.navbar.elem = this.dom.container.find('#navbar');
		
		
		/**
		 * Listen to click on dropdown-toggle item on navbar
		 */
		this.dom.dropdown.toggle.on('click', function(e) {
			e.preventDefault();
			
			var $parent = $(this).parent();
			
			if($parent.hasClass('open')) {
				$parent.removeClass('open');
			}
			else {
				/** Hide all dropdown-menus */
				that.dom.dropdown.elem.removeClass('open');
				
				$parent.addClass('open');
			}
		});
		/**
		 * Listen to click event on burger-icon
		 */
		this.dom.toggleNavbar.on('click', function(e) {
			e.preventDefault();
			
			that.showNavbar('navbar');
		});
		/**
		 * @name: showNavbar
		 * @param:
		 * @description: display the targetted element
		 */
		this.showNavbar = function() {
			if(that.dom.navbar.elem.hasClass('open')) {
				that.dom.navbar.elem.removeClass('open');
				that.dom.toggleNavbar.removeClass('open');
			}
			else {
				that.hideNavbar();
				that.dom.navbar.elem.addClass('open');
				that.dom.toggleNavbar.addClass('open');
			}
		};
		/**
		 * @name: hideNavbar
		 * @param: -
		 * @description: hide all navbars
		 */
		this.hideNavbar = function() {
			that.dom.navbar.all.removeClass('open');
			/** close burger-icon */
			that.dom.toggleNavbar.removeClass('open');
		};
	};
};

var navbar = new Navbar($('#main-navbar'));
navbar.init();
              
            
!
999px

Console