CSS Dropdowns - Detailed Overview

Introduction to CSS Dropdowns

A dropdown menu is a UI element that allows users to select one option from a list of options. This example demonstrates how to create a basic dropdown menu using CSS.

Example Dropdown Menu

.navbar {
    background-color: #333;
    overflow: hidden;
    border-radius: 5px;
}

.navbar a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 14px 20px;
    text-decoration: none;
}

.navbar a:hover {
    background-color: #575757;
}

.dropdown {
    float: left;
    overflow: hidden;
}

.dropdown .dropbtn {
    font-size: 16px;
    border: none;
    outline: none;
    color: white;
    padding: 14px 20px;
    background-color: #333;
    cursor: pointer;
}

.dropdown:hover .dropbtn {
    background-color: #575757;
}

.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;
    border-radius: 5px;
}

.dropdown-content a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {
    background-color: #ddd;
}

.dropdown:hover .dropdown-content {
    display: block;
}