Adjust the positioning of individual navigation items to the right using Bootstrap 5

My website's navbar is built using Bootstrap 5 and I'm looking to make some adjustments. In the screenshot provided, I am trying to move the last three navigation items to the right side.https://i.sstatic.net/kbVKD.png

I attempted using ms-auto, but it ended up moving all of the navigation items to the right. What I really want is just those last three items to be aligned to the right.

Answer №1

Consider utilizing 2 different ul classes:

<link href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b2bfbeb5b2b5b3a0b1eeaab0bcbbbaa79ebfb4abb4b9">[email protected]</a>/font/bootstrap-icons.css" rel="stylesheet"/>
<script src="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8aa8a5a5aeaba6a4b7ece9eabfaacbabdbdafbaafeea1be">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<link href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="69b1bcbcadabaea8bbaaeff4babeaba5">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>


<!-- Navigation-->
<nav class="navbar navbar-expand-md navbar-dark bg-primary">
    <div class="container-fluid">
        <a class="navbar-brand abs" href="#">Navbar 1</a>
        <button class="navbar-toggler ms-auto" type="button" data-bs-toggle="collapse" data-bs-target="#collapseNavbar">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse" id="collapseNavbar">
            <ul class="navbar-nav">
                <li class="nav-item active">
                    <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="//example.com">Example</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#myAlert" data-bs-toggle="collapse">Link</a>
                </li>
            </ul>
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="" data-bs-target="#myModal" data-bs-toggle="modal">About</a>
                </li>
                <li class="nav-item active">
                    <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="//example.com">Example</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Answer №2

If you want to shift the last three navigation items to the right, one way to achieve this is by dividing the navigation items into two separate ul elements. The ul that contains the right-aligned items should have the class ms-auto.


<nav class="navbar navbar-expand-lg">
            <div class="container-fluid">
                <a class="navbar-brand" href="#">Navbar</a>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav">
                        <!-- left aligned items -->
                    </ul>
                    <ul class="navbar-nav ms-auto">
                        <!-- right aligned items -->
                    </ul>
                </div>
            </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

Unable to locate the type definition file for 'jquery'

After updating my NuGet packages, I encountered an issue where I can no longer compile due to an error related to the bootstrap definition file not being able to find the jquery definition file within my project. Prior to the update, the directory structu ...

Using the $.get() method within a loop of .each(), retrieve the specific $(this) value within the $.get function

Apologies for the poorly worded question, but I'm struggling to find a better way to phrase it. I'm currently working with a .each() loop where I need to update a specific css() parameter of each item in the loop. However, I can't seem to g ...

I am having trouble getting the HTML button to trigger the JS script

Following my previous inquiry on Stack Overflow, I attempted to implement the JavaScript file but encountered an issue when trying to trigger its functions by clicking an HTML button. After the JS script requests for money and a soda product code, I found ...

How to display text on a new line using HTML and CSS?

How can I properly display formatted text in HTML with a text string from my database? The text should be contained within a <div class="col-xs-12"> and nested inside the div, there should be a <pre> tag. When the text size exceeds the width o ...

What is the best way to loop through each and every HTML element present on a webpage?

My current code looks like this: $(document).ready(function() { $(this).each(function(index) { delete style; var style = $(this).attr("style"); document.write(style); )); }); Unfortunately, I'm facing an issue where it keeps throwi ...

Tips for correctly cloning a table row:

Currently, I am engaged with a Django project that involves incorporating a form within a table structure. <table name="mytable" id="table_purchase" role="grid"> <thead> <tr> <th class="text-center" hidden>No</th& ...

Is it possible to preserve the <canvas> elements to use for future animation frames?

Currently, I am working on a graph visualization project that involves complex calculations being done on an HTML5 canvas. My goal is to create an interactive animation where the graph remains fixed, but additional elements are overlaid as the mouse moves ...

Sending a div class as a parameter to a JavaScript function

Wondering if it's possible to pass a div's class into a JavaScript function. I'm using SquareSpace so adding an id to the div is not an option, but it works fine with divs that have ids. JQuery is already loaded. This is my current train of ...

JavaScript drag functionality is jerky on iPads, not seamless

I am currently attempting to implement a feature where I can drag a div (#drag) within its parent container (#container) using only pure JavaScript. This functionality is specifically required to work on iPad devices only. After writing a script that func ...

KineticJS: Applying a filter to an image does not result in the image having a stroke

Working with KineticJS version 5.1.0 I encountered an issue where a KineticJS image that had a stroke lost the stroke after applying a filter to it. I have created a demo showcasing this problem, which can be viewed on JSFiddle. Here is the code snippet: ...

How can I create a clickable <div> element containing multiple links and trigger only one action?

Within my code, there is a <div> element that has been made clickable. Upon clicking this <div>, the height and text expand using the jQuery function $(div).animate();. While this functionality works as intended, I am encountering a slight issu ...

selenium.common.exceptions.ElementNotInteractableException: Error: the element cannot be interacted with

My current programming project involves using selenium webdriver with Twitter for fun, but I've run into a frustrating issue. The problem arises when I attempt to input text into the tweet box: https://i.stack.imgur.com/Zxwvg.png To activate the ele ...

Positioning content using absolute in CSS3 for a unique layout that pushes down other elements

I'm working on a responsive webpage where I have to insert different content with varying heights. The layout includes: An image at the top with a red gradient overlay. Below that, a div with a blue background to create a seamless transition bet ...

Tips for selecting a radio button using its unique identifier

I'm having trouble getting this code to work properly. I can't seem to find any mistakes in the code, can someone please assist me in resolving this issue? <html> <body> <input type="radio" name="radio" id="radio1">Site 1< ...

What steps can I take to completely remove JavaScript from an HTML document?

To eliminate the <script> tags in the HTML, I can utilize regex just like this $html = preg_replace('#<script(.*?)>(.*?)</script>#is','', $html); While this approach works well, dealing with inline JavaScript require ...

Having Trouble with jQuery toggleClass

I'm currently working on a project where I have implemented a button that displays a menu when clicked. I am attempting to change the color of the button when it is active, however, the toggleClass function is not behaving as expected. Below is the co ...

How to store selected checkbox values in an array using AngularJS

Check out this code snippet: <tr ng-repeat="doc in providers"> <td><input type="checkbox" ng-true-value="{{doc.provider.Id}}" ng-false-value="" ng-model="ids"></td> </tr> {{ids}} I am trying to store the values of ...

"Enhance your webpage with a captivating opaque background image using Bootstrap

I'm new to exploring Bootstrap and I am currently experimenting with options for displaying content with a semi-transparent background image. Currently, I am using a "well" but I am open to other suggestions. I have managed to place the image inside t ...

Scraping data from a support portal using JSOUP

I am currently learning how to utilize jSoup for web scraping purposes on this specific portal that focuses on LAN switching and routing discussions. Link to the portal My goal is to extract information from a list of topics, specifically identifying sol ...

What is the best way to implement a responsive navigation bar for mobile devices using Bootstrap 4 integrated with Vue

I've been putting in a lot of effort to create a responsive navbar using Bootstrap 4 with Vue. Here is the code in my App.vue file: NavBar <b-navbar-nav> <b-nav-item href="#">Link</b-nav-item> <b-nav-item href="#" disabled ...