CSS Navbar - Detailed Overview

Introduction to CSS Navbar

A navigation bar (navbar) is a user interface element used to navigate between different sections or pages of a website. This example demonstrates a simple responsive navbar using CSS flexbox and media queries.

Example Navbar

.navbar {
    display: flex;
    background-color: #333;
    padding: 10px;
    border-radius: 5px;
}

.navbar a {
    color: white;
    padding: 14px 20px;
    text-decoration: none;
    text-align: center;
    font-weight: bold;
}

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

.navbar .menu {
    flex: 1;
}

.navbar .menu a {
    display: inline-block;
}

.navbar .menu a.active {
    background-color: #4CAF50;
}

.navbar .toggle-btn {
    display: none;
}

/* Responsive Layout */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
    }

    .navbar .toggle-btn {
        display: block;
        cursor: pointer;
        font-size: 18px;
        color: white;
        background-color: #333;
        border: none;
        padding: 10px;
        text-align: center;
    }

    .navbar .menu {
        display: none;
        flex-direction: column;
    }

    .navbar .menu.active {
        display: flex;
    }

    .navbar .menu a {
        padding: 10px;
        border-top: 1px solid #575757;
    }
}