Enhancing Navbar with Additional Components

Enhancing Your Bootstrap Navbar

Welcome back! In the previous lessons, you learned how to create a basic Bootstrap navbar, add a navbar toggler for responsiveness, and set up navigation links that connect to different sections of a webpage.

This lesson takes it up a notch by enhancing your navbar with additional components. This will make your website more interactive and user-friendly. Let's see what you'll learn this time.

What You'll Learn

In this lesson, you will learn how to add extra components to your Bootstrap navbar to make it more functional and visually appealing:

  1. Dropdown Menus: You'll learn how to incorporate dropdown menus into your navbar. Dropdowns are useful for organizing multiple sub-options under a single navbar item.

    For example:

    XML
    <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
            Features
        </a>
        <ul class="dropdown-menu">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
        </ul>
    </li>

    This snippet shows how to add a dropdown menu under the "Features" navbar item, offering multiple sub-options for users to choose from.

    In the above code snippet:

    • <li class="nav-item dropdown">: Defines the list item as a dropdown.
    • <a class="nav-link dropdown-toggle": Triggers the dropdown menu when clicked.
    • <ul class="dropdown-menu">: Contains the dropdown items.
    • dropdown-item: Class used for each dropdown link.
    • <hr class="dropdown-divider">: Adds a divider line between dropdown items.
  2. Forms within the Navbar: You'll explore how to add forms, such as a search bar, directly within your navbar. This feature is common on many websites to enhance user experience.

    Here's an example:

    XML
    <form class="d-flex ms-auto">
        <input class="form-control me-2" type="search" placeholder="Search">
        <button class="btn btn-success btn-lg" type="submit">Search</button>
    </form>

    Using a search bar within the navbar allows users to quickly find content on your website, making the navigation experience more efficient.

    In the above code snippet:

    • <form class="d-flex ms-auto">: Defines the form with a flexible layout and aligns it to the right (ms-auto).
    • <input class="form-control me-2": Creates a search input field with some margin to the right (me-2).
    • <button class="btn btn-success btn-lg": Adds a large, green search button to submit the form.
Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal