I'm trying to get my nav links to float to the right of my navbar, but I can't get it to work. I've tried using the ".float-right", "float-xs-right", and "justify-content-end" bootstrap 4 class, along with using "float: right !important;" in my CSS file, and it still won't work.
Here is the HTML for the navbar of my website:
<div id="navbar" class="navbar navbar-fixed-top">
<div class="container">
<div class="row">
<div class="navbar-brand">
<img src="images/logo.png" width="88px">
Scervino Lawn Service
</div>
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link" href="home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact">Contact</a>
</li>
</ul>
</div>
</div>
</div>
And here is the CSS:
#navbar {
box-shadow: 0px 0px 11px #000;
padding: 0;
}
#navbar .navbar-brand {
font-size: 1.6em;
font-weight: bold;
color: #9CCC58;
}
I'm relatively new to the Bootstrap 4 framework, so it's possible that I might just be making a dumb mistake, but hopefully someone can help me. :(
You can use
.justify-content-between
on the parent.row
to move the flex children to the far edges of the row.I tried with Bootstrap 4.0.0 Alpha 6 and it works, here's the example: https://repl.it/JwMq/0
I just added this:
And a extra
</div>
Update 2018 - Bootstrap 4.0.0
The original answer no longer works in Bootstrap 4.0.0, and it's not good practice to use Bootstrap's
.row
in the navbar component. The.row
should only be used for grid columns.Now that Bootstrap 4 is flexbox, one way to align navbar components is using the auto-margin utility classes, such as
ml-auto
which is a shortcut for CSSmargin-left:auto
. This can be used to push thenav
to the right...https://www.codeply.com/go/ZAGhCX5lpq
Or the flexbox utils like
justify-content-between
can be used on thecontainer
inside the navbar...Just notice that in this case
justify-content-between
works because there are only 2 navbar components (navbar-brand and nav).