Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap navbar align want align to the right

I'm trying to align the navbar to the right. When I use the .pull-right class it's pushing the navbar too much to the right: "off the grid".

What am I doing wrong?

Code:

<div class="row">
<div class="span3 top_logo"><img src="images/logo_svart.png" width="177" height="60" alt="BETA Team Performance" /></div>
    <div class="span9">
        <div class="navbar navbar-static-top">
            <div class="navbar-inner">
                <div class="container">
                    <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><strong>MENY <i class="icon-chevron-down icon-white"></i></strong>
                    </button>
                    <div class="nav-collapse collapse">
                        <ul class="nav pull-right">
                            <li class="active"><a href="#">Start</a></li>
                            ...
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

like image 767
Sickan007 Avatar asked Feb 27 '13 17:02

Sickan007


4 Answers

For anyone arriving here who's using Bootstrap v3, just use the included .navbar-right on the list element:

<div class="collapse navbar-collapse navbar-ex1-collapse">
    <ul class="nav navbar-nav navbar-right">
      <!-- … -->
    </ul>
</div>
like image 100
hyponym Avatar answered Oct 22 '22 07:10

hyponym


The problem arises because in bootstrap-responsive.css the margin-right is set to 0.

Jsfiddle with a basic mockup See in browser

So you have to provide it with some number to look appropriate, like below:

.navbar .nav.pull-right {
     float: right;
    margin-right: 98px; /*set margin this way in your custom styesheet*/
  }

The html code to create your desired effect can be written in the following way :

<div class="conatiner">
<div class="row-fluid">
    <div class="span2 top_logo">
        <img width="177" height="60" alt="BETA Team Performance" src="http://placehold.it/177x60">
    </div>
    <div class="span10">
        <div class="navbar navbar-static-top">
            <div class="navbar-inner">
                <div class="container">
                    <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
                    <button data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar"
                    type="button"><strong>MENY <i class="icon-chevron-down icon-white"></i></strong>

                    </button>
                    <!-- Everything you want hidden at 940px or less, place within here -->
                    <div class="nav-collapse collapse ">
                        <!-- .nav, .navbar-search, .navbar-form, etc -->
                        <ul class="nav pull-right">
                            <li class="active"><a href="#">Home</a>
                            </li>
                            <li><a href="#">Link</a>
                            </li>
                            <li><a href="#">Link</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
      </div>
    </div>
  </div>
like image 33
Shail Avatar answered Oct 22 '22 08:10

Shail


try putting your pull-right class on the div.collapse. That may do the trick.

like image 4
Kristian Avatar answered Oct 22 '22 08:10

Kristian


In Boostrap 4 you can use ml-auto to align the menu to the right:

<div class="navbar-nav ml-auto">
like image 2
mbadeveloper Avatar answered Oct 22 '22 09:10

mbadeveloper