Dropdowns
A dropdown menu is a navigation pattern used to hide and show a list of links when a user hovers over a menu item. It is commonly used in websites to organize navigation in a compact way.
Basic Dropdown Structure
In HTML, we create dropdowns using nested <ul> and <li> elements.
Example:
Styling the Dropdown with CSS
Example: Here is a full working example with CSS to make the dropdown interactive on hover:
Output:
.webp)
Basic Dropdown Structure
In HTML, we create dropdowns using nested <ul> and <li> elements.
Example:
<nav> <ul> <li class="Lev-1"> <a href="#">Level-1</a> <ul> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> <li><a href="#">Link 4</a></li> </ul> </li> </ul></nav>
Styling the Dropdown with CSS
Example: Here is a full working example with CSS to make the dropdown interactive on hover:
<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <title>CSS Dropdown Menu</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f4f4; }
.gfg { font-size: 40px; font-weight: bold; color: #009900; text-align: center; margin: 20px 0; }
p { font-size: 20px; font-weight: bold; text-align: center; }
nav { background: #333; padding: 10px 0; }
nav>ul { list-style: none; margin: 0 auto; padding: 0; display: flex; justify-content: center; }
nav ul li { position: relative; margin: 0 10px; }
nav ul li a { display: block; padding: 10px 20px; background-color: #990; color: white; text-decoration: none; transition: background 0.3s; }
nav ul li a:hover { background-color: #090; }
/* Dropdown Styles */ nav ul li ul { display: none; position: absolute; top: 100%; left: 0; background: #333; list-style: none; min-width: 150px; }
nav ul li ul li { width: 100%; }
nav ul li:hover>ul { display: block; } </style></head>
<body>
<div class="gfg">Quipoin</div> <p>CSS Dropdown Navigation Menu</p>
<nav> <ul> <li class="Lev-1"> <a href="#">Level-1</a> <ul> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> <li><a href="#">Link 4</a></li> </ul> </li> </ul> </nav>
</body>
</html>
Output:
.webp)
Key Point
- Hover-based interaction (no JavaScript required)
- Simple and mobile-friendly layout
- Easy to customize (colors, size, animation)