Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap - floating navbar button right

I'm using the bootstrap navigation bar, but I want to float one of the buttons to the right instead of the left as it already is. Here's the HTML:

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">   <div class="container">     <div class="navbar-header">       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">         <span class="sr-only">Toggle navigation</span>         <span class="icon-bar"></span>         <span class="icon-bar"></span>         <span class="icon-bar"></span>       </button>       <a class="navbar-brand" href="#">Project name</a>     </div>     <div class="collapse navbar-collapse">       <ul class="nav navbar-nav">         <li class="active"><a href="#">Home</a></li>         <li><a href="#about">About</a></li>         <li><a href="#contact" class="navbar-nav pull-right">Contact</a></li>       </ul>     </div>   </div> </div> 

I've tried using nav navbar-nav navbar-right, float:right, and pull-right. I really don't know what else I could do. Any help is appreciated.

JSFiddle

like image 614
Michael Blake Avatar asked Feb 04 '14 05:02

Michael Blake


2 Answers

In bootstrap 4 use:

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

This will push the navbar to the right. Use mr-auto to push it to the left, this is the default behaviour.

like image 168
Henry Avatar answered Oct 02 '22 14:10

Henry


You would need to use the following markup. If you want to float any menu items to the right, create a separate <ul class="nav navbar-nav"> with navbar-right class to it.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <html>    <head>    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />  </head>    <body>    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">      <div class="container">        <div class="navbar-header">          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">              <span class="sr-only">Toggle navigation</span>              <span class="icon-bar"></span>              <span class="icon-bar"></span>              <span class="icon-bar"></span>            </button>          <a class="navbar-brand" href="#">Project name</a>        </div>        <div class="collapse navbar-collapse">          <ul class="nav navbar-nav">            <li class="active"><a href="#">Home</a></li>            <li><a href="#about">About</a></li>            </ul>          <ul class="nav navbar-nav navbar-right">            <li><a href="#contact">Contact</a></li>          </ul>        </div>      </div>    </div>  </body>    </html>
like image 33
Ravimallya Avatar answered Oct 02 '22 13:10

Ravimallya