There are a lot of examples of drop down menus written on JS in the internet. But it is also possible to create a drop down menu without using javascript. This method has one huge benefit – your site will work faster without loading extra JS code.
HTML
<menu> <div class="menu-item"> <a href="#">item-1</a> <div class="menu-submenu"> <p><a href="#">subitem-1</a></p> <p><a href="#">subitem-2</a></p> <p><a href="#">subitem-3</a></p> </div> </div> <div class="menu-item"> <a href="#">item-2</a> <div class="menu-submenu"> <p><a href="#">subitem-1</a></p> <p><a href="#">subitem-2</a></p> <p><a href="#">subitem-3</a></p> </div> </div> <div class="menu-item"> <a href="#">item-3</a> <div class="menu-submenu"> <p><a href="#">subitem-1</a></p> <p><a href="#">subitem-2</a></p> <p><a href="#">subitem-3</a></p> <p><a href="#">subitem-4</a></p> <p><a href="#">subitem-5</a></p> </div> </div> </menu>
CSS
.menu-item { position: relative; display: inline-block; } .menu-submenu { padding: 10px 0; border: 1px solid #473F3C; background: #fff; display: none; position: absolute; top: 18px; left: 0; white-space: nowrap; } .menu-item:hover .menu-submenu { display: block; /* here we show submenu on hover event */ }
This is how our menu will looks like.
The menu will work with all modern browsers.