Moving the Bootstrap-5 navbar button in a horizontal direction from left to right

I am looking to reposition the buttons on this bootstrap5 navbar from the left side to the right side. I need help figuring out how to accomplish this using css or bootstrap5. Can anyone provide some guidance?

Here is my current code:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b6bbbba0a7a0a6b5a494e1fae7fae4f9b5b8a4bcb5e5">[email protected]</a>/dist/css/bootstrap.min.css" 
    rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" 
    crossorigin="anonymous">

 <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086a67677c7b7c7a6978483d263b263825696478606939">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container">
          <a class="navbar-brand" href="#">
            <h1>Pondadb</h1>
          </a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
        
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav ml-auto">
              <li class="nav-item active">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">About</a>
              </li>
              <li class="nav-item">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Contact</a>
              </li>
              <li class="nav-item">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Login</a>
              </li>
              <li class="nav-item">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Sign-Up</a>
              </li>
            </ul>
          </div>
        </div>
      </nav>

Answer №1

The class .mr-auto in Bootstrap 4 corresponds to margin-right: auto;, however, in Bootstrap 5, the correct class is .me-auto.

If you want to align elements to the right with margin-left: auto;, use ms-auto in Bootstrap 5.

For more information on spacing utilities in Bootstrap 5, refer to Spacing · Bootstrap v5.3

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e1838e8e959295938091a1d4cfd2cfd1cc808d918980d0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90f2ffffe4e3e4e2f1e0d0a5bea3bea0bdf1fce0f8f1a1">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container">
    <a class="navbar-brand" href="#">
      <h1>Pondadb</h1>
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item active">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Contact</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Login</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Singn-Up</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

Answer №2

To adjust the alignment of your element, try switching "mr-auto" to "ml-auto". This change corresponds to using Bootstrap's margin-right: auto styling, which positions an element on the right side. If I'm interpreting your needs correctly, you're aiming for a right-aligned layout, in which case changing it to margin-left: auto = ml-auto should do the trick.

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

turn the cube shape into one with smooth, rounded corners

Does anyone know how to create a cube with rounded corners using three.js? I've heard it's not possible with CSS. Any guidance on how to achieve this? Check out this link for an example /* |------------------------------------------| | MelonHTM ...

Displaying inner arrays in an Angular2 MatTable

Welcome to my initial post on Stack Overflow, where I hope to communicate my query clearly. I am currently attempting to develop a table with dynamic columns. However, I am encountering difficulty in comprehending how to bind matColumnDef to a specific el ...

Is your data coming in as NaN?

I am currently developing a basic webpage that has the capability to calculate your stake and determine your return, reminiscent of a traditional betting shop. As of now, I have successfully hard coded the odds into my page. However, while testing my code ...

Outline of a Bootstrap row

I am trying to create a row layout where the background extends beyond the designated row area. The desired design is shown in the image, with an additional white space before the actual text of the row. However, when I attempt to start a new row and set ...

If I choose a different option from the dropdown list, I would like a textbox to appear

Hey there, I have a list of industries and one of the options is "Other". When a user clicks on "Other", a text box should appear for them to specify. I'm struggling to make this work using Django AJAX. Any help would be appreciated! <div class ...

What is your preferred method for adjusting the size of Divs on your webpage according to the screen size?

Currently working on a coding test and facing an issue with the display of div sizes across different screens. The discrepancy in appearance between my laptop and a Mac computer monitor is causing some trouble, as on my small laptop the divs appear overs ...

The "getJson" function fails to execute when attempting to run a Python

I've come across a simple code snippet, but for some reason, my getjson function isn't working as expected. My Python script properly prints a JSON encoded value. Does anyone have any suggestions? HTML <!DOCTYPE html> <html> <h ...

What steps can be taken to create a two-column layout using the provided HTML code?

I'm having trouble getting my CSS to work properly in IE 8. Any suggestions on how to fix this? Here's the simplified HTML code I'm using: <div id="column-content"> <div id="content"> <p>This is some text</ ...

Concealing two div elements based on string content

I am working on a unique Wordpress blog post layout that showcases personnel profile cards, displaying 12 individuals at a time. Depending on whether or not a person has a Twitter handle entered in the backend, certain elements should either be shown or hi ...

Having trouble removing a DOM element with jQuery?

Hey there, I need your help with a jQuery issue I'm facing. I am currently working on cloning a div element that contains a span with a click event attached to it. The purpose of the click event is to remove the newly cloned section from the DOM. Whil ...

Unable to write to csv file in UTF-8 using PHP fwrite, experiencing issues

Looking for assistance with handling PHP fwrite as CSV file is displaying incorrect characters. The output appears like this: općšpšćšćšp ćpšćpšćp šćpšćpšć This is the PHP code being used fo ...

Absolute positioning in Tailwind CSS on an absolute div

I'm having trouble incorporating 4 absolutes within this div. I can't seem to figure out why they are extending beyond the boundaries of the div. Can anyone spot the error? Check out this Tailwind CSS example <div class="bg-blue-100 h-40 ...

Creating a drop-down menu within an HTML table along with a D3 bar chart

How can I implement a drop-down menu allowing the user to choose a time interval for this HTML table and d3 bar chart? The time intervals needed are: Now, 24 hours, 48 hours, 72 hours, 1 week, and 1 month. I am relatively new to creating dynamic tables and ...

Refreshing the PHP variable without needing to refresh the page

Recently, I've delved into the world of JSON and PHP programming. I am currently working on a web page that displays data from a file called file.py. This data is intended to be visualized on a gauge that updates every second. var gauge1; var x = ...

Angular 8: Bridging the gap between two players with a shared singleton service

I've been working on creating a multiplayer Battleships game, and although the basic functionality is there, I'm struggling to connect two players to the same game. Any assistance would be greatly appreciated! My goal is to create a service that ...

Hyperlink to an HTML file located in a different directory and refresh the URL

Within my controller, I am managing an array of strings that represent various folder names. My goal is to retrieve the index.html file from each of these folders: $scope.folderNames = ['DCB', etc] I aim to create a link on my HTML page for eac ...

having difficulty applying a border to the popup modal

Currently, I am utilizing a Popup modal component provided by the reactjs-popup library. export default () => ( <Popup trigger={<button className="button"> Guide </button>} modal nested > {(close: any) =&g ...

Distinguish among various formats with cgi python

Within my html file, there exist numerous forms all referencing the same python cgi script. Here is an example: <html> <body> <form method="POST" name="form1" action="script.cgi" enctype="multipart/data-form"> .... </form> ... < ...

Unable to create a responsive design for this box

I've been attempting to place text and a button inside a box, but I'm encountering issues with fitting them on medium and small screens. So far, the methods I've tried have not been successful. Below is the code I am currently using: * { ...

Background image in Bootstrap not covering entire web page

I am facing an issue where the background image is confined within the constraints of the login panel, and I'm unsure why. My goal is for the image to span the full width and height of the browser window. Any assistance on this matter would be greatly ...