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

              
                <nav id="top-menu">
	<div class="container">
		<ul role="menubar">
			<li role="presentation"><a role="menuitem" href="#0">Item 1</a></li>
			<li role="presentation">
				<h2>Item 2</h2>
				<ul>
					<li role="presentation"><a role="menuitem" href="#0">Item 2-1</a></li>
					<li role="presentation"><a role="menuitem" href="#0">Item 2-2</a></li>
				</ul>
			</li>
			<li role="presentation">
				<h2>Item 3</h2>
				<ul>
					<li role="presentation"><a role="menuitem" href="#0">Item 3-1</a></li>
					<li role="presentation"><a role="menuitem" href="#0">Item 3-2</a></li>
					<li role="presentation" class="spacer"></li>
					<li role="presentation">
						<a role="menuitem" href="#0">Item 3-3</a>
						<ul>
							<li role="presentation"><a role="menuitem" href="#0">Item 3-3-1</a></li>
							<li role="presentation"><a role="menuitem" href="#0">Item 3-3-2</a></li>
							<li role="presentation"><a role="menuitem" href="#0">Item 3-3-3</a></li>
						</ul>
					</li>
					<li role="presentation"><a role="menuitem" href="#0">Item 3-4</a> </li>
					<li role="presentation"><a role="menuitem" href="#0">Item 3-5</a></li>
				</ul>
			</li>
			<li role="presentation">
				<h2>Item 4</h2>
				<ul>
					<li role="presentation"><a role="menuitem" href="#0">Item 4-1</a></li>
					<li role="presentation"><a role="menuitem" href="#0">Item 4-2</a></li>
				</ul>
			</li>
			<li role="presentation">
				<h2>Item 5</h2>
				<ul>
					<li role="presentation"><a role="menuitem" href="#0">Item 5-1</a></li>
					<li role="presentation"><a role="menuitem" href="#0">Item 5-2</a></li>
					<li role="presentation">
						<a role="menuitem" href="#0">Item 5-3</a>
						<ul>
							<li role="presentation"><a role="menuitem" href="#0">Item 5-3-1</a></li>
							<li role="presentation"><a role="menuitem" href="#0">Item 5-3-2</a></li>
							<li role="presentation"><a role="menuitem" href="#0">Item 5-3-3</a></li>
						</ul>
            </li>
					<li role="presentation"><a role="menuitem" href="#0">Item 5-4</a></li>
				</ul>
			</li>
		</ul>
	</div>
</nav>
              
            
!

CSS

              
                /**
 * Accessible and keyboard-usable full-CSS multilevel dropdown menu
 */

/* Skip straight to line 95 to see all the magic */

/* Let's define some values */

@color-secondary: #4caf50;
@color-secondary-alternate: #388e3c;

@top-menu-height: 3em;

/* Let's add a little reset and some basic common styles (thanks Eric Meyer!) */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
main, menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
	box-sizing: border-box;

	&::before, &::after{
		box-sizing: border-box;
	}
}
article, aside, details, figcaption, figure, 
footer, header, hgroup, main, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

html{
	font-family: Tahoma, Geneva, Kalimati, sans-serif;
	line-height: 1.5;
	background-color: #f5f5f5;
	-webkit-text-size-adjust: 100%;
	text-rendering: optimizeLegibility;
}

a{
	color: inherit;
	text-decoration: underline;

	&:hover{
		text-decoration: none;
	}
	&:focus{
		text-decoration: none;
	}
	&:active{
		opacity: .8;
	}
}

.container{
	width: 60em;
	margin-left: auto;
	margin-right: auto;
}


/* All the magic starts here! */

#top-menu{
	position: relative;
	z-index: 999;
	height: @top-menu-height;
	background-color: @color-secondary;
	color: #fff;

	a, h2{
		position: relative;
		z-index: 5;
		display: block;
		padding: .5em;
		margin: 0;
		line-height: 2;
		font-size: inherit;
		font-weight: inherit;
		text-decoration: none;
		text-align: center;
		white-space: nowrap;
		background-color: @color-secondary;
	}
	a:hover, a:focus{
		background-color: @color-secondary-alternate;
	}
	h2{
		cursor: default;
	}
	
	ul{
		margin: 0;
		list-style: none;

		&>li{
			margin: 0;

			&.spacer{
				height: 1em;
			}
		}
	}

	&>.container>ul{
		&::after{
			&:extend(.pseudo-clear);
		}
		&>li{
			float: left;
			width: 20%;
			overflow: hidden;
			height: @top-menu-height;

			&:nth-child(1){
				width: 10%;
			}
			&:nth-child(3){
				width: 30%;
			}

			&>a:not(:last-child), &>h2:not(:last-child){
				// padding-right: @top-menu-height;

				&::after{
					content: '﹀';
					position: absolute;
					z-index: 6;
					top: 0;
					right: 0;
					bottom: 0;
					padding: .5em;
					width: @top-menu-height;
					height: @top-menu-height;
					font-weight: bold;
					text-align: center;
					line-height: @top-menu-height - .5em;
				}
			}

			&>ul{
				position: relative;
				z-index: 1;
				background-color: @color-secondary;
				box-shadow: 0 0 .5em rgba(0,0,0,.35);

				&>li{
					position: relative;
					overflow: hidden;
					border-top: 1px solid @color-secondary-alternate;

					&>a:not(:last-child){
						// padding-right: @top-menu-height;

						&::after{
							content: '⟩';
							position: absolute;
							z-index: 6;
							top: 0;
							right: 0;
							bottom: 0;
							padding: .5em;
							width: @top-menu-height;
							height: @top-menu-height;
							font-weight: bold;
							text-align: center;
							line-height: @top-menu-height - 1em;
						}
					}

					&>ul{
						position: absolute;
						top: 0;
						left: 100%;
						min-width: 100%;
						z-index: 0;
						background-color: @color-secondary;
						box-shadow: 0 0 .5em rgba(0,0,0,.35);
						border-left: 1px solid @color-secondary-alternate;
						
						&>li:not(:first-child){
							border-top: 1px solid @color-secondary-alternate;
						}
					}
					
					&:hover, &.open{
						overflow: visible;
					}
				}
			}
			
			&:hover, &.open{
				overflow: visible;
			}
		}
    /* Handling the right-side sub-menus to show sub-elements on the left instead of right */
		&>li:last-child>ul>li{
			&>a:not(:last-child){
				// padding-right: .5em;
				// padding-left: @top-menu-height;

				&::after{
					content: '⟨';
					right: auto;
					left: 0;
				}
			}

			&>ul{
				// left: -100%;
				left: auto;
				right: 100%;
				border-right: 1px solid @color-secondary-alternate;
				border-left: none;
			}
		}
	}
}

/* There are only 3 levels for now, but you can see how it wors and adapt it for more if necessary (but is it really?) */
              
            
!

JS

              
                /* The menu is totally usable without JavaScript, but the few lines make it more beautiful */

var topMenu = document.getElementById('top-menu');

function topMenuOpen (e) {
	this.classList.add('open');

	var elem = this;
	while (elem.parentNode !== topMenu) {
		if (elem.nodeName.toLowerCase() == 'li'){
			elem.classList.add('open');
		}
		elem = elem.parentNode;
	}
	if (e && e.target && e.target.nodeName.toLowerCase() === 'a') {
		e.preventDefault();
	}
}
function topMenuClose (e) {
	this.classList.remove('open');

	var elem = this;
	while (elem.parentNode !== topMenu) {
		if (elem.nodeName.toLowerCase() == 'li'){
			elem.classList.remove('open');
		}
		elem = elem.parentNode;
	}

	if (e && e.target && e.target.nodeName.toLowerCase() === 'a') {
		e.preventDefault();
	}
}



Array.prototype.forEach.call(topMenu.querySelectorAll('ul>li'), function (li) {
	if(!li.getElementsByTagName('ul')) {
return;
	}

	li.addEventListener('mouseleave', topMenuClose.bind(li), false);
	li.addEventListener('mouseenter', topMenuOpen.bind(li), false);
});

Array.prototype.forEach.call(topMenu.querySelectorAll('li>a, li>h3'), function (link) {
	if(!link.parentNode.getElementsByTagName('ul')) {
		return;
	}

	link.addEventListener('blur', topMenuClose.bind(link.parentNode), false);
	link.addEventListener('focus', topMenuOpen.bind(link.parentNode), false);
});
              
            
!
999px

Console