Snippets

Simple Pure CSS Drop Down Menu

June 25, 2017

menu drop-down

Simple Pure CSS Drop Down Menu
<nav> <ul> <li><a href="#">Home</a></li> <li class="submenu"><a href="#">Portfolio</a> <ul > <li><a href="#">Animation</a></li> <li><a href="#">Game Design</a></li> <li><a href="#">Web Design</a></li> </ul> </li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> /*Styling the main menu*/ nav ul li { float: left; list-style: none; } nav ul li a { color: white; background: cornflowerblue; padding: 10px; text-decoration: none; display:inline-block; width: 100px; } nav ul li a:hover { background: cornflowerblue; } /* Styling the sub menu */ .submenu { position: relative; } .submenu ul { position: absolute; padding:0; margin:0; display: none; } .submenu li{ display: block; background: lightsteelblue; color: white; float: none; width: 100%; } /* Styling drop down links */ .submenu li a { background: transparent; padding:10px; display: block; } .submenu li a:hover { background: gray; } /* Showing Submenu on hover*/ .submenu:hover ul { display: block; }

Related Content

Easy Way to Fix Anchor Links Scrolling Too Far

Stories

Easy Way to Fix Anchor Links Scrolling Too Far

Fixed navbar is a very popular way of displaying navigation when a page is scrolled, but you could run into a small detail that needs to be addressed.

How to Avoid Page Flickering When Scrollbars are Dynamically Shown or Hidden?

Stories

How to Avoid Page Flickering When Scrollbars are Dynamically Shown or Hidden?

There are certain cases when you want to dynamically manipulate the page height which will result in flickering.

Changing the Mouse Cursor in CSS With the cursor Property

Stories

Changing the Mouse Cursor in CSS With the cursor Property

Using CSS to change the cursor on your website is a great way to add a little bit of personality to your site.