Bootstrap navbar align want align to the right

75,594

Solution 1

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>

Solution 2

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>

Solution 3

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

Solution 4

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

<div class="navbar-nav ml-auto">
Share:
75,594

Related videos on Youtube

Sickan007
Author by

Sickan007

Updated on August 10, 2022

Comments

  • Sickan007
    Sickan007 over 1 year

    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>
    

  • Sickan007
    Sickan007 about 11 years
    It dident solve the problem, the navbar moved like 20pixels to the left but more than half of the navbar is still outside the "grid". Any other suggestion?

Related