Dremendo Tag Line

CSS Navigation Menu

Navigation

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

Creating a Navigation Menu using HTML and CSS

A navigation menu is an essential part of any website. It provides a list of options or links to help users navigate through the content or different sections of the website or application. It serves as a roadmap for users to access various pages, features, or sections within the website or application.

Let's create a simple horizontal and vertical navigation menu using HTML and CSS.

video-poster

Horizontal Navigation Menu

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Horizontal 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;
        }
    </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="#">Products</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Query</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</body>

</html>

Vertical Navigation Menu

<!doctype html>
<html>

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

    <!-- Internal CSS -->
    <style>
        .menu-bar {
            display: inline-block;
        }

        .menu {
            list-style-type: none;
            padding: 0;
            margin: 0;
            background-color: #1F2021;
        }

        .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;
        }
    </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="#">Products</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Query</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</body>

</html>

You can further enhance your navigation menu by:

  • Changing the background color.
  • Adding different hover effects to links.
  • Adjusting margin, padding, and fonts to suit your website's design.