Centered Navigation Links with Logo Positioned on the Left in Bootstrap 5

I've been struggling to create a centered navbar in Bootstrap 5 with left-aligned brand logo. Despite trying various flexbox options, I can only manage to center the nav links within a flex container. However, the collapse feature functions correctly.

<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top navbar-default">
  <div class="container-fluid">
    <a href="#" class="navbar-brand me-auto">
      <img style="height: 45px" src="https://lanman2018.ieee-lanman.org/files/2016/01/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bf8eae6fbe7eea6e7e4ece4cbb9f3a5fbe5ec">[email protected]</a>">
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar2">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="navbar-collapse collapse justify-content-center" id="navbar">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link" href="#">page link/a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="dropdown" aria-expanded="false">dropdown</a>
          <ul class="dropdown-menu" aria-labelledby="dropdown">
            <li>
              <a class="dropdown-item" href="#">2nd Page</a>
            </li>
            <li>
              <a class="dropdown-item" href="#"> This is a really long page nameS</a>
            </li>
            <li>
              <a class="dropdown-item" href="#">still a long name</a>
            </li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">about us</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Contact Page</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

When I position the logo as absolute, I achieve the desired outcome but encounter an issue where the collapsed nav button overlaps with the logo. I suspect I'm overlooking something simple since frontend isn't my forte.

Here's a jsfiddle link showcasing both solutions I've been experimenting with https://jsfiddle.net/0s24hLmf/

Answer №1

If you adjust the toggler to the right using ms-auto, it should function properly...

<nav class="navbar navbar-expand-md navbar-dark bg-dark navbar-default">
    <div class="container-fluid">
        <a href="/index.php" class="navbar-brand nav-logo me-auto position-absolute top-0">
            <img style="height: 45px" src="https://lanman2018.ieee-lanman.org/files/2016/01/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a495b574a565f1756555d557a&l=74447746404032464044">[email protected]</a>">
        </a>
        <button class="navbar-toggler ms-auto" type="button" data-bs-toggle="collapse" data-bs-target="#navbar2">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse justify-content-center" id="navbar2">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="#">Page Link</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="dropdown2" aria-expanded="false">dropdown</a>
                    <ul class="dropdown-menu" aria-labelledby="dropdown">
                        <li><a class="dropdown-item" href="#">2nd Page</a>
                        </li>
                        <li><a class="dropdown-item" href="#"> This is a really long page nameS</a></li>
                        <li><a class="dropdown-item" href="#">still a long name</a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">about us</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Contact Page</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Live Demo

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 to prevent hover effects on the outer div when hovering over the inner div?

I am facing an issue with disabling hover effects on an outer div when hovering over an inner button. I have tried various methods but haven't been successful in achieving the desired outcome. .container { background-color: #e6e6e6; width: 400p ...

Updating the color scheme of the selected nav-item and showcasing the corresponding page in relation to the navbar selection

I have been trying various methods, but I am unable to change the background color of an active navigation item and also display the corresponding page. Important: The jQuery code below successfully changes the background color of the navbar list item. Ho ...

You need to click the form submit image twice in order to make it work

Struggling to get a standard opt-in form to work with an image submit button. The script works fine with a regular submit button, but the image button requires two clicks initially and then one click after unless the page is refreshed. I believe there mig ...

Appear and disappear gradually when hovering

When hovering over #one, the class .hidden is applied to #first. I have added a script to make .hidden fade out using transition: ease-in 0.3s;, but I am having trouble getting the fade in effect to work. I attempted adding transition: ease-in 0.3s; to #fi ...

Personalize the file button for uploading images

I have a button to upload image files and I want to customize it to allow for uploading more than one image file. What is the logic to achieve this? <input type="file" />, which renders a choose button with text that says `no files chosen` in the sa ...

Modify the background hue of the checkbox to resemble a button when selected

Is there a way to create a checkbox that resembles a button in appearance? I have managed to achieve this, but I am facing an issue with changing the background color of the button when it is checked. Currently, the button turns light-grey when checked, bu ...

Adding a unique styling to a div with a custom css class

I am experiencing an issue with my CSS file (approval.css) that is defined as a resource and applied to my XPage. Within the css, there is a specific line of code: .appNavBackground {background-color:#ffffd6 ;} When I try to apply this styleClass to a di ...

Different div elements are clashing with each other when it comes to hiding and

Having added multiple div elements with different IDs, I am facing an issue where clicking one div displays it while hiding the others. I am looking for a solution to prevent conflicts between the divs. Any suggestions on what might be causing this problem ...

the pop-up modal function is malfunctioning

I can't get my pop up to work properly. When I click the button, the screen dims as if a pop up is going to appear, but nothing shows up. Can someone please assist me with this issue? Here is the HTML file: <!DOCTYPE html> <html lang="en"&g ...

Are there CSS styles that target specific elements?

My goal is to design a unique and custom theme for blender.stackexchange. However, I am facing an issue where the rules I implement only affect certain tags when viewed in FF 29.0.1 Despite all tag elements having the same classes, parent elements, etc., ...

What is the best way to stop event bubbling in react-router-dom when using the <Link> component?

Hey there! I have a situation that I need help with. I tried putting the Link around the whole post so that I could prevent bubbling for individual buttons, but for some reason stopPropagation() is not working as intended. Following advice from another s ...

Struggling to center a div within another div using margin auto

Hey there, I'm looking for some help with my code. Here's what I have: .center{ width: 100%; margin: 0 auto; border: 1px solid red; } .nav{ background: #606060; width: 90%; } HTML <!DOCTYPE html> <html> < ...

Sending JSON data to Python CGI script

I've successfully set up Apache2 and got Python running without any issues. However, I'm facing a problem with two pages - one is a Python Page and the other is an HTML page with JQuery. Could someone guide me on how to correctly make my ajax p ...

Assign a CSS class to a DIV depending on the vertical position of the cursor

The website I am currently developing is located at Within the site, there is a collection of project titles. When hovering over a project title, the featured image is displayed directly below it. I would like to change the positioning of these images to ...

Using CSS to design a table-like structure with rows that span multiple columns

I am trying to generate a table dynamically using CSS and a JSON array. For example: In the code snippet provided, I have assigned a class of 'spannedrow' to span certain cells in the table, although the class is not defined yet. This is just ...

Link the parameters of two polymer elements within a repeat template

In this scenario, my goal is to securely bind attr and attr1. These two variables should be independent from the variable data, unlike other attributes in use. I want each iteration to have its own set of bound components, rather than sharing one data obje ...

Tips for preventing conflicts between JQuery libraries

Need help resolving conflicts between jQuery libraries in a multiple step form with a date and time picker dropdown menu. The form works when one library is disabled, but not both. Tried online solutions with no success. <!DOCTYPE html> <html l ...

Prevent HTML from being escaped in data-binding while utilizing repeat-templates in Polymer

Hey there! <template repeat="{{item in items}}"> <div layout horizontal> <div>{{item['content']}}</div> <div>{{item['more_content'])}</div> ...

Zebra lines overlooking unseen details

Imagine having a table where rows can be dynamically assigned classes such as .hidden, which hide those rows using CSS. The rows are styled with alternating colors, like this: tr:nth-child(even) { background-color: $light-grey; } But here's the ...

Leveraging font as a comprehensive repository of icons

I have been experimenting with using entypo as the icon source for my web application. The UI technology I am working with is ZK. However, I encountered an issue when trying to include an icon from that font by using: <span sclass="entypoWhite">&am ...