Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 -- Moving links to the right of the navbar with a toggle button [duplicate]

I was attempting to move the links from the left of the navbar to the right side and it wouldn't let me. I've tried floating it to the right and nothing had happened, same with position:relative; right: 200px; and padding-right: -200px;. If anyone has any other suggestions it would be appreciated thank you.

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">

    <button class="navbar-toggler navbar-toggler-right" 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>

    <a class="navbar-brand" href="index.html">

        <img id="logo" src="images/logo.png" width="200" class="d-inline-block align-top" alt="">

    </a>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">

        <ul class="navbar-nav mr-auto">

            <li class="nav-item">
                <a class="nav-link active text-white" href="index.html">Home <span class="sr-only">(current)</span></a>
            </li>

            <li class="nav-item">
                <a class="nav-link text-white" href="services.html">Services</a>
            </li>

            <li class="nav-item">
                <a class="nav-link text-white" href="portfolio.html">Portfolio</a>
            </li>

            <li class="nav-item">
                <a class="nav-link text-white" href="about.html">About</a>
            </li>

        </ul>

    </div>
</nav>
like image 218
Cameron Foster Avatar asked Jan 18 '17 05:01

Cameron Foster


People also ask

How to align items to the right in Bootstrap 5 navbar?

By default, the Bootstrap 5 navbar components are aligned to the left. Here, we will learn to align items to the right. As the navbar is built with flexbox. The navbar items can be aligned using flex utility. Use .justify-content-end class on collapse menu to justify items to the right.

What are the different types of navigation bars in Bootstrap?

1 Navigation Bars. With Bootstrap, a navigation bar can extend or collapse, depending on the screen size. ... 2 Inverted Navigation Bar 3 Navigation Bar With Dropdown. Navigation bars can also hold dropdown menus. 4 Right-Aligned Navigation Bar. ... 5 Navbar Buttons 6 Navbar Forms. ... 7 Navbar Text. ... 8 Fixed Navigation Bar. ...

How to add links inside a navigation bar in HTML?

A standard navigation bar is created with the.navbar class, followed by a responsive collapsing class:.navbar-expand-xl|lg|md|sm (stacks the navbar vertically on extra large, large, medium or small screens). To add links inside the navbar, use a <ul> element with class="navbar-nav".

What is the use of navbar-brand in Bootstrap?

The .navbar-brand class is used to highlight the brand/logo/project name of your page: ... When using the .navbar-brand class on images, Bootstrap 4 will automatically style the image to fit the navbar vertically.


3 Answers

You're using the .mr-auto so you have margin-right: auto !important and the nav-items left aligned.
If you change the class to .ml-auto you have margin-left: auto !important and your nav-items are right aligned

like image 199
julianstark999 Avatar answered Oct 19 '22 05:10

julianstark999


Modify some css in bootstrap:

Used justify-content: end; to start content for end

.mr-auto {
    margin-right: 0 !important;
}
.navbar-toggleable-md .navbar-collapse {         
    -webkit-justify-content: flex-end;
    justify-content: flex-end;  
} 

Here is fiddle code: https://jsfiddle.net/0ewenvcb/2/

like image 1
Mukesh Ram Avatar answered Oct 19 '22 05:10

Mukesh Ram


After trying all options, the menu-icon (navbar-toggler-icon) was not moving to the right in Bootstrap 4.1.
I tried the following work around:
Under @media (max-width:575px) - added .navbar-header {width:100%;}, and under class .menu-icon (I named it menu-icon) {justify-content:end;}.
This moved both the navbar-brand and menu-icon to the right. To move the navbar-brand to the left, in the HTML added class mr-auto to navbar-brand. This worked just fine for me.

like image 1
A G Aranha Avatar answered Oct 19 '22 05:10

A G Aranha