我的bootstrap导航栏有问题。我最近找到了一种在导航栏中居中项目的方法,但事实是当菜单折叠时,这些项目会保持水平对齐而不是垂直对齐。
这就是我现在所拥有的:
<div class="container-fluid">
<nav class="navbar navbar-inverse navbar-fixed-top fixfollow center">
<div class="navbar-inner">
<div class="container">
<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>
<a class="navbar-brand hidden-lg" href="/"><i class="fa fa-home fa-lg"></i></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
<a class="navbar-brand visible-lg" href="/"><i class="fa fa-home fa-lg"></i></a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
和重要的CSS:
.center .nav,
.center .nav > li
{
float:none;
display:inline-block;
/*display:inline; /* ie7 fix */
/*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}
.center .navbar-inner {
text-align:center;
}
.center .dropdown-menu {
text-align: left;
}
有了这个,我的项目在导航栏中居中,但在collopased菜单中水平显示。我希望有一些帮助来改变它,以便在没有折叠菜单的情况下取回引导折叠菜单的经典行为(我的意思是垂直)而不改变居中的项目。
答案 0 :(得分:1)
只需在媒体查询中应用您的规则:
@media (min-width: 767px) {
YOUR RULES HERE
}
请参阅工作示例代码段。
@media (min-width: 767px) {
.center .nav,
.center .nav > li {
float: none;
display: inline-block;
vertical-align: top;
}
.center .navbar-inner {
text-align: center;
}
.center .dropdown-menu {
text-align: left;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<nav class="navbar navbar-inverse navbar-fixed-top fixfollow center">
<div class="navbar-inner">
<div class="container">
<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>
<a class="navbar-brand hidden-lg" href="/"><i class="fa fa-home fa-lg"></i></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
<a class="navbar-brand visible-lg" href="/"><i class="fa fa-home fa-lg"></i></a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
<li>
<a href="/link">link</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
答案 1 :(得分:0)
也许,尝试通过带有下拉菜单的 .navbar-header 更改类 .dropdow-menu (如何取消设置)。