Dremendo Tag Line

CSS Dropdown Navigation Menu

Navigation

In this lesson, we will learn how to create a dropdown navigation menu using HTML and CSS.

Creating a Dropdown Navigation Menu using HTML and CSS

A dropdown menu provides a clean way to organize and display sub-navigation menu. It allows users to select one option from a list of choices. Dropdown menus are commonly used in web development to save space on a page or to organize and hide a large number of options until the user needs them.

video-poster
Example
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Navigation Menu</title>

    <!-- Internal CSS -->
    <style>
        .menu-bar {
            height: 45px;
            background-color: #1F2021;
            display: inline-block;
        }

        .menu {
            list-style-type: none;
            padding: 0;
            margin: 0;
        }

        .menu li {
            float: left;
        }

        .menu li a {
            display: block;
            line-height: 45px;
            padding: 0 15px;
            text-decoration: none;
            color: #BEBEBE;
        }

        .menu li a:hover {
            background-color: #004571;
            color: white;
        }

        .sub-menu {
            list-style-type: none;
            padding: 0;
            margin: 0;
            position: absolute;
            background-color: #3A4B56;
            display: none;
        }

        .sub-menu li {
            float: none;
        }

        .sub-menu li a:hover {
            background-color: #486C36;
        }

        .menu li:hover .sub-menu {
            display: block;
        }

        .menu li:hover .dd-menu {
            background-color: #004571;
            color: white;
        }
    </style>
</head>

<body>
    <nav class="menu-bar">
        <ul class="menu">
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#" class="dd-menu">Products</a>
                <ul class="sub-menu">
                    <li><a href="#">Product Option 1</a></li>
                    <li><a href="#">Product Option 2</a></li>
                    <li><a href="#">Product Option 3</a></li>
                    <li><a href="#">Product Option 4</a></li>
                </ul>
            </li>
            <li><a href="#" class="dd-menu">Services</a>
                <ul class="sub-menu">
                    <li><a href="#">Service Option 1</a></li>
                    <li><a href="#">Service Option 2</a></li>
                    <li><a href="#">Service Option 3</a></li>
                    <li><a href="#">Service Option 4</a></li>
                </ul>
            </li>
            <li><a href="#">Query</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</body>

</html>