使用Twitter Bootstrap 3.
我有一个固定的导航栏,菜单项向右对齐,在navbar-collapse div的ul内添加.pull-right.
当导航在小屏幕上崩溃,并单击打开它,导航项目不应该是100%的宽度,而是大约30%,并向右拉.
已经解决了:
@media (max-width: 767px) { .navbar-nav.pull-right { float: none!important; } }
但是想知道是否有更好的方式来做.
导航栏的代码是:
<!-- Fixed navbar --> <div class="navbar navbar-fixed-top"> <div class="container"> <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> <a class="navbar-brand" href="/"> <img src="application/assets/img/main-logo.png" alt=""> </a> </div> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav pull-right"> <li class="active"><a href="#">Menu 1</a></li> <li><a href="#about">Menu 2</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu 3 <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 class="dropdown-header">Nav header</li> <li><a href="#">Separated link</a></li> <li><a href="#">One more separated link</a></li> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu 4 <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 class="dropdown-header">Nav header</li> <li><a href="#">Separated link</a></li> <li><a href="#">One more separated link</a></li> </ul> </li> <li><a href="#about">Menu 5</a></li> </ul> </div><!--/.nav-collapse --> </div> </div>
解决方法
我看了手册!
需要使用.navbar-right而不是.pull-right,其中已经内置了媒体查询来引导.