twitter-bootstrap Bootstrap 导航栏对齐想要向右对齐

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15118310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:31:27  来源:igfitidea点击:

Bootstrap navbar align want align to the right

twitter-bootstrapnavbar

提问by Sickan007

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".

我正在尝试将导航栏向右对齐。当我使用 .pull-right 类时,它会将导航栏向右推太多:“脱离网格”。

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>

采纳答案by Shail

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

出现问题是因为在 bootstrap-responsive.cssmargin-right中设置为 0。

Jsfiddle with a basic mockup See in browser

带有基本模型的 Jsfiddle在浏览器中查看

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 :

可以按以下方式编写用于创建所需效果的 html 代码:

<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>

回答by hyponym

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

对于使用Bootstrap v3到达这里的任何人,只需使用包含.navbar-right在列表元素中的内容:

<div class="collapse navbar-collapse navbar-ex1-collapse">
    <ul class="nav navbar-nav navbar-right">
      <!-- … -->
    </ul>
</div>

回答by Kristian

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

尝试将您的pull-right课程放在div.collapse. 这可能会奏效。

回答by mbadeveloper

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

在 Boostrap 4 中,您可以使用ml-auto将菜单向右对齐:

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

回答by chp7

If you dowant to pull something all the way to the right outside the grid (like select language or social buttons) you can create a simple class and add to the <ul class="nav navbar-nav language">and style it like so .language {right:50px;position:absolute;}. Works really well with using the .navbar-brandas a logo to your far left (from an Art Directors eye, anyways).

如果您确实想将某些东西一直拉到网格外的右侧(例如选择语言或社交按钮),您可以创建一个简单的类并添加到<ul class="nav navbar-nav language">并设置样式.language {right:50px;position:absolute;}。将.navbar-brand用作最左侧的徽标非常有效(无论如何,从艺术总监的角度来看)。

回答by greg

This here worked for me. Putting pull-rightin the div.collapsedoesn't work - it has to be in the un-ordered list class.

这对我有用。把pull-rightdiv.collapse不工作-它必须是在非有序列表类。

<div class="nav-collapse collapse navbar-responsive-collapse">

 <ul class="nav navbar-nav pull-right">