adiush
adiush

Reputation: 55

Bootstrap4 Navbar - Spacing Elements (Right, Center, Left)

I want to put my content in a navbar to 3 different 'columns'. All i want is logo on the left (checked) some nav-items on the center (checked) and the last element (Get The App) on the right and that's a problem.

Here's my code:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#"><img src="img/Logo.png"></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavDropdown">
        <ul class="navbar-nav mx-auto">
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Home
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            </div>
        </li>
        <li class="nav-item active">
            <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Pricing</a>
        </li>
        </ul>
        <ul class="navbar-nav mr-auto">
        <li class="nav-item">
            <a class="nav-link" href="#">Get The App</a>
        </li>
        </ul>
    </div>
</nav>

and CSS:

.navbar-nav.mr-auto ul li a.nav-link {
justify-content: right;
display: flex;
flex-wrap: wrap; }

And this is my result:

navbar

I would appreciate any help, thanks ;)

Upvotes: 0

Views: 459

Answers (2)

blackcityhenry
blackcityhenry

Reputation: 727

you have to get rid of the margin-right: auto !important of the class .mr-auto.

Simply remove the class .mr-auto if you don't need it.

https://codepen.io/blackcityhenry/pen/bQYxyV

Upvotes: 1

tao
tao

Reputation: 90038

Remove the mr-auto class from your last .navbar-nav.
That class applies margin-right: auto !important to your element, which makes it push against the right margin, just like mx-auto applies the same auto to both x sides (left and right).

See it working:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#"><img src="img/Logo.png"></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavDropdown">
        <ul class="navbar-nav mx-auto">
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Home
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            </div>
        </li>
        <li class="nav-item active">
            <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Pricing</a>
        </li>
        </ul>
        <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" href="#">Get The App</a>
        </li>
        </ul>
    </div>
</nav>

Upvotes: 1

Related Questions