我需要在引导程序中使用完全右对齐的导航栏,但问题是我的品牌在左侧,但我需要它向右侧移动。虽然我可以使用navbar-right
选项将其他列表项放在右侧。
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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 pull-right" href="#">CesaStack</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">بیاب</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
答案 0 :(得分:34)
将品牌移至导航栏标题上方,并将其设为右侧导航栏。
这使您的品牌在桌面视图中正确显示,并在移动视图中保留,将菜单按钮正确保留为最右边的元素。
<nav class="navbar navbar-default" role="navigation">
<a class="navbar-brand navbar-right" href="#">CesaStack</a>
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<!-- snip -->
</div>
</nav>
答案 1 :(得分:8)
品牌位于左侧,即使它有.pull-right
类,因为它包含在
<div class="navbar-header">
..
<a class="navbar-brand pull-right" href="#">CesaStack</a>
</div>
如果您将其放在外面,就在.navbar-header
- &gt; </div>
之后,那么它将按照应有的方式对齐。
在这个小提琴中看到你的代码 - &gt;的 http://jsfiddle.net/9BfjX/ 强>
答案 2 :(得分:7)
您需要使用的是 navbar-right
,而不是右拉
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<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>
**LOGO OR HEADER NAME HERE**
</div>
<div class="navbar-collapse navbar-right collapse">
**OTHER MENU OR FORM HERE**
</div><!--/.navbar-collapse -->
</div>
答案 3 :(得分:-2)
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Left</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">right</a></li>
<li><a href="#">right</a></li>
<li><a href="#">right</a></li>
</ul>
</div>
</nav>