Material Design Nav Bar with Hover Dropdown

Material Design Nav Bar with Hover Dropdown
Code Snippet:Material Nav Header w/ Aligned Dropdowns
Author: Cole Waldrip
Published: January 19, 2024
Last Updated: January 22, 2024
Downloads: 352
License: MIT
Edit Code online: View on CodePen
Read More

This code snippet helps you to create Material Design like nav bar with hover dropdown. It uses HTML and CSS to structure and style the navigation. The navigation bar allows for easy organization and access to different sections of a website. It helps create a sleek and intuitive navigation experience for users.

You can use this code for website navigation. It provides a sleek, organized menu for easy browsing.

How to Create Material Design Nav Bar With Hover Dropdown

1. First of all, load the Normalize CSS and Prefixfree JS by adding the following CDN links into the head tag of your HTML document.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>

2. Copy the HTML structure for the nav bar as follows. It consists of <header>, <nav>, and various <div> elements containing links.

<header>
<nav>
<div>
<a><span>Tab </span>1</a>
	<div>
	<a>Link 1</a>
	<a>Link 2</a>
	<a>Link 3</a>
	<a>Link 4</a>
	<a>Link 5</a>
	<a>Link 6</a>
</div>
</div>
<div>
	<a><span>Tab </span>2</a>
	<div>
	<a>Link 1</a>
	<a>Link 2</a>
	<a>Link 3</a>
	<a>Link 4</a>
	<a>Link 5</a>
	<a>Link 6</a>
</div>
	</div>
	<div>
	<a><span>Tab </span>3</a>
	<div>
	<a>Link 1</a>
	<a>Link 2</a>
	<a>Link 3</a>
	<a>Link 4</a>
	<a>Link 5</a>
	<a>Link 6</a>
	</div>
	</div>
	<div>
	<a><span>Tab </span>4</a>
	<div>
	<a>Link 1</a>
	<a>Link 2</a>
	<a>Link 3</a>
	<a>Link 4</a>
	<a>Link 5</a>
	<a>Link 6</a>
</div>
</div>
	<div>
	<a><span>Tab </span>5</a>
	<div>
	<a>Link 1</a>
	<a>Link 2</a>
	<a>Link 3</a>
	<a>Link 4</a>
	<a>Link 5</a>
	<a>Link 6</a>
	</div>
	</div>
	<div>
	<a><span>Tab </span>6</a>
	<div>
	<a>Link 1</a>
	<a>Link 2</a>
	<a>Link 3</a>
	<a>Link 4</a>
	<a>Link 5</a>
	<a>Link 6</a>
	</div>
		</div>
		</nav>
</header>
<h1>Enjoy!</h1>
<p>CodePen by Cole Waldrip</p>

3. Include the following CSS code within <style> tags or link it to your HTML file. This CSS defines the styling and behavior of the navbar.

@import url(https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic);
* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
}

body {
		font-family: 'Roboto', Arial, sans-serif;
		background-color: #ebebeb;
		overflow-x: hidden;
		text-align: center;
}

header {
		width: 100%;
		height: 50px;
		background-color: #f44355;
		box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

header > nav > div {
		float: left;
		width: 16.6666%;
		height: 100%;
		position: relative;
}

header > nav > div > a {
		text-align: center;
		width: 100%;
		height: 100%;
		display: block;
		line-height: 50px;
		color: #fbfbfb;
		transition: background-color 0.2s ease;
		text-transform: uppercase;
}

header > nav > div:hover > a {
		background-color: rgba(0, 0, 0, 0.1);
		cursor: pointer;
}

header > nav > div > div {
		display: none;
		overflow: hidden;
		background-color: white;
		min-width: 200%;
		position: absolute;
		box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
		padding: 10px;
}

header > nav > div:not(:first-of-type):not(:last-of-type) > div {
		left: -50%;
		border-radius: 0 0 3px 3px;
}

header > nav > div:first-of-type > div {
		left: 0;
		border-radius: 0 0 3px 0;
}

header > nav > div:last-of-type > div {
		right: 0;
		border-radius: 0 0 0 3px;
}

header > nav > div:hover > div {
		display: block;
}

header > nav > div > div > a {
		display: block;
		float: left;
		padding: 8px 10px;
		width: 46%;
		margin: 2%;
		text-align: center;
		background-color: #f44355;
		color: #fbfbfb;
		border-radius: 2px;
		transition: background-color 0.2s ease;
}

header > nav > div > div > a:hover {
		background-color: #212121;
		cursor: pointer;
}

h1 {
		margin-top: 100px;
		font-weight: 100;
}

p {
		color: #aaa;
		font-weight: 300;
}

@media (max-width:600px) {
		header > nav > div > div > a {
				margin: 5px 0;
				width: 100%;
		}
		header > nav > div > a > span {
				display: none;
		}
}

Adjust the content of the links and tabs within the HTML structure to match your website’s navigation needs. Modify colors, text, and layout if required.

That’s all! hopefully, you have successfully integrated this nav bar with the dropdown on your website. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X