Toggle navigation
☰
HTML
CSS
Scripting
Database
<!DOCTYPE html> <html> <head> <title>Dropdown Navigation Menu Example</title> <style> body { font-family: sans-serif; margin: 0; } nav { background-color: #333; } nav ul { list-style-type: none; margin: 0; padding: 0; display: flex; } /* Style for each list item */ nav li { position: relative; /* Required for the dropdown positioning */ } /* Style for links */ nav li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } nav li a:hover { background-color: #111; } /* Style for the dropdown container (hidden by default) */ .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } /* Style for links inside the dropdown */ .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover { background-color: #f1f1f1; } /* Show the dropdown menu on hover */ nav li:hover .dropdown-content { display: block; } </style> </head> <body> <nav> <ul> <li><a href="#">Home</a></li> <li> <a href="#">Products</a> <div class="dropdown-content"> <a href="#">Electronics</a> <a href="#">Clothing</a> <a href="#">Books</a> </div> </li> <li> <a href="#">Services</a> <div class="dropdown-content"> <a href="#">Consulting</a> <a href="#">Design</a> <a href="#">Development</a> </div> </li> <li><a href="#">Contact</a></li> </ul> </nav> <div style="padding: 20px;"> <h2>Hover over the menu items</h2> <p>Hover over "Products" or "Services" to see the dropdown menus. We used <code>position: absolute;</code> on the dropdown content so that it doesn't push the rest of the page layout when it appears.</p> </div> </body> </html>