我无法弄清楚如何将品牌徽标放入我的bootstrap导航栏中。我希望徽标显示在导航栏的左侧,链接应位于中心。
https://jsfiddle.net/spon1r82/2/
在jsfiddle示例中,您可以看到链接居中,品牌徽标实际上位于正确的网站上,但徽标和链接似乎位于两个不同的行中。如何在与链接相同的行中移动徽标并保持相同的分区(徽标(左),链接(居中))?
HTML
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand Logo</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" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Stories</a></li>
<li><a href="#">Videos</a></li>
<li><a href="#">Photos</a></li>
</ul>
</div>
</div>
</nav>
CSS
/*NAVBAR*/
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
答案 0 :(得分:3)
答案 1 :(得分:1)
删除.navbar-nav
上的宽度以使其正常工作。请参阅下面的示例。
编辑我没有看到zgood的评论,他也有答案。
/*NAVBAR*/
.navbar-nav {
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand Logo</a>
<!-- 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>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Stories</a></li>
<li><a href="#">Videos</a></li>
<li><a href="#">Photos</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>