Navigation bar collapse items are not properly aligned in the layout

My navbar collapse button is not aligning the items in the dropdown properly. I suspect it has to do with the way I have structured the divs. How can this issue be fixed?

<nav class="navbar navbar-expand-md navbar-light mb-4 row">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    
    <div class="col-4 text-left collapse navbar-collapse" id="navbarCollapse">
          <ul class="navbar-nav mr-auto">
            <li class="nav-item" id="better_candidate">
                <a class="nav-link" href="">A Better Candidate</a>
            <li class="nav-item" id="better_employer">
                <a class="nav-link" href="">A Better Employer</a>
            <li class="nav-item" id="better_stuff">
                <a class="nav-link" href="">Better Stuff</a>
          </ul>
            </div>

    <div class="col-4 text-center">
        <a class="navbar-brand" href="{% url 'a_better_place:home' %}">
            A Better Place
        </a>
    </div>

    <div class="col-4 text-right collapse navbar-collapse" id="navbarCollapse">
          <ul class="navbar-nav ml-auto">
                <li class="nav-item" id="about_us">
                    <a class="nav-link" href=""> About Us </a>
              <li class="nav-item" id="contact">
                  <a class="nav-link" href="{% url 'a_better_place:contact' %}">
                      Contact
                  </a>   
          </ul>
          
      </div>
</nav>

Image

Answer №1

Typically, the col and row classes are not utilized in the navbar. Additionally, it is important to avoid using the same ID for two navbar-collapse lists. Instead, a class can be used and referenced in the navbar-toggler's data-target.

To center the branding on larger screens, the flex order property can be employed.

For future reference, when posing a question, providing a functional snippet allows others to better understand the issue at hand.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="680a07071c1b1c1a0918285c465e4658">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc9e9393888f888e9d8cbcc8d2cad2cc">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>

<nav class="navbar navbar-expand-md navbar-light mb-4">
    <!-- exclude row -->
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-navbar-collapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand order-md-2 " href="{% url 'a_better_place:home' %}">
        A Better Place
    </a>
    <!-- ensure unique IDs -->
    <div class="collapse navbar-collapse dual-navbar-collapse">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item" id="better_candidate">
                <a class="nav-link" href="">A Better Candidate</a>
            <li class="nav-item" id="better_employer">
                <a class="nav-link" href="">A Better Employer</a>
            <li class="nav-item" id="better_stuff">
                <a class="nav-link" href="">Better Stuff</a>
        </ul>
    </div>
    <!-- eliminate div around brand -->

    <!-- delete col-4 text-right -->
    <div class="collapse navbar-collapse dual-navbar-collapse order-md-3">
        <ul class="navbar-nav ml-auto">
            <li class="nav-item" id="about_us">
                <a class="nav-link" href=""> About Us </a>
            <li class="nav-item" id="contact">
                <a class="nav-link" href="{% url 'a_better_place:contact' %}">
                    Contact
                </a>
        </ul>

    </div>
</nav>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way in JQuery to apply the CSS of one element to another selected element?

I'm curious if there is a JQuery function available that can be used to transfer the exact CSS styles from one element to another. I want all the CSS properties to be applied without any additional inheritance. For example: <div id="d1"> &l ...

Learn how to dynamically apply a CSS attribute for a set period of time using jQuery and automatically revert it back to its original state after 2 seconds

Is there a way to apply a CSS attribute to a specific element (like a div) for only 2 seconds? Here is what I have tried so far: HTML: <div class="custom-div">bar</div> <input class="button" type="button" value="press me" /> JQuery: $ ...

Enhancing the Search Bar in Bootstrap 4 Dashboard Template: A Step-by-Step Guide

Recently got my hands on the Bootstrap 4 Dashboard template and decided to enhance it by adding a form to the top search bar. However, I encountered an issue where the search bar shrinks and loses its original design. If you want to check out the Bootstra ...

IE7, IE6 display margins differently compared to other browsers

Can anyone help with an issue I'm having with a CSS ul list menu? #header-container #header ul.top-nav { float: left; margin: 20px 0 20px 10px; } #header-container #header ul.top-nav li { float: left; margin-right: 8px; border-rig ...

Creating a promotional slide-up feature on a website page using jQuery and Bootstrap

Is there a way to achieve a promotional slide-up similar to the one showcased below using the features provided by Bootstrap/jQuery? https://i.sstatic.net/ZMLeD.png ...

What is the process for activating the Placeholder feature in a Floating Input Field in a React application

Having trouble changing the placeholder value in a Bootstrap-based floating input. I want to display default text as a placeholder and allow users to edit it. Any suggestions? Check out this example on CodeSandbox <div class="form-floating mb-3&qu ...

Loading items into the select menu

In my database, I have a table with 3 columns: ID, TITLE, TEXT. These will be used to populate select options in a form. When a user makes a selection, a script will take the title and text, make some adjustments, and store it in a different table. My que ...

What is the method for invoking a function with arguments within an HTML `<p>` element?

I am looking to display like and dislike percentages on cards. <v-card v-if="software[2] == searched || searched == ''" class="software-card" > <h3>{{ software[2] }}</h3> ...

Conceal or reveal radio buttons according to information in a table

How can I dynamically add and remove values from a table based on radio button selections? My goal is to add the selected value to the table and hide it from the radio button list, and if the value is deleted from the table, I want to show it back in the r ...

Safari does not support onunload when the page is closing

<body onunload="notReady()"> <script > function notReady(){ alert("closing") } </script> </body> It seems that the script works only when refreshing the page or clicking a link on the page, but not when closing the pa ...

Issue with the JQuery FadeIn effect on my website when a div is repositioned for visibility

I have been working on revamping an existing website at www.gjelavoie.com. To enhance the user experience, I decided to use jquery fadein() and fadeout() functions for displaying my Contact form without visitors having to temporarily access the main page. ...

Avoiding code duplication in Angular: tips for optimizing functions

Is there a way to avoid repeating the same for loop for a second variable and use only one? I'm trying to apply the "Don't repeat yourself" method here. Should I consider using an array? JS: var app=angular.module('xpCalc', []); app.c ...

Challenges Encountered When Inputting Year in ReactJS Date Picker Component

I've encountered a problem with a date input component in my ReactJS project and need some assistance with resolving two issues: Problem 1: Year Input Length The first issue is that the year input field allows six digits, but I want to restrict it to ...

Setting the width of an SVG element to match the width of the <text> element inside it

Within this JSFiddle project - https://jsfiddle.net/xtxd6r8t/ - there is an <svg> element containing text inside a <text> tag. Upon inspection of the <svg> and delving into the <text> element, it's noticeable that the width of ...

What causes the <td> element to extend beyond the boundaries of the <table>?

I need to add next and previous buttons to a <td> that has an asp:DropDownList. However, when I do this, the <td> ends up overflowing the width of the table. Here is the edited code snippet with the entire table included: <table class=" ...

Exploring the Differences in Site Navigation: PHP/HTML, Ajax, and CSS/Javascript

Lately, I've been weighing the pros and cons of using AJAX for my website navigation to transfer only necessary updated HTML elements. Alternatively, if there isn't a significant difference between new elements and current ones, just loading the ...

The fonts in node.js are not functioning as expected, without displaying any error messages

I'm having trouble implementing custom fonts on my website. Despite following the correct file structure, the fonts do not seem to be loading. My project files are organized in the following manner: https://gyazo.com/5ee766f030290e5b2fa42320cc39f10b ...

Including a .css file in ejs

I'm currently developing an application using Node.js (express) with EJS, and I'm facing an issue while including a .css file in it. When I tried the same setup as a standalone HTML-CSS project, it worked perfectly fine. How can I include the CSS ...

Excessive vertical space is utilized by the vertical images in the CSS grid image gallery

My responsive CSS grid gallery is experiencing issues with vertical images disrupting the layout, as they appear at full size instead of remaining square like the others. How can I fix this problem? Thank you! Below is the code snippet: <div id=" ...

Imagine a scenario where clicking on an image causes it to be rotated or

Could use some assistance figuring out what's missing here. I've added a random photo from Wiki, similar in size to the images I'll be working with. The images will vary in size, but I want them to always remain visible within the browser w ...