最近我调整了bootstrap的菜单大小。现在问题是菜单项顶部的菜单项的文本位置。
我想将菜单项显示在菜单标题的中心。菜单项已在中心位置对齐。
这是我的代码:http://jsfiddle.net/y8v0rd9g
的CSS:
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
.navbar {
position: relative;
min-height: 80px;
margin-bottom: 20px;
border: 1px solid transparent
}
答案 0 :(得分:0)
您可以使用解决方案http://jsfiddle.net/y8v0rd9g/3/
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
.navbar {
position: relative;
margin-bottom: 20px;
border: 1px solid transparent
}
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-12">
<nav class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">
<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" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown<strong class="caret"></strong></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 class="form-control" type="text">
</div>
<button type="submit" class="btn btn-default">
Submit
</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<strong class="caret"></strong></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>
</nav>
</div>
</div>
</div>
从 .nav
中删除了最小高度答案 1 :(得分:0)
如果您使用浏览器的开发工具,则会看到您的链接(ul.nav
)实际上是垂直居中对齐的,但列表在nav
元素之前结束。那是因为你在导航栏上设置了min-height: 80px
。我建议也添加填充,但不是@LKG的方式。相反,请删除最小高度规则,并仅将顶部和底部填充添加到.navbar
。这样项目保持中心对齐。更新了fiddle并更新了代码:
.navbar {
position: relative;
margin-bottom: 20px;
padding: 12px 0;
border: 1px solid transparent
}