我最终使用了一个轻微的变体,我不喜欢使用display:table
并想使用它flexbox
。
CSS:
.navbar .nav {
margin: 0;
display: flex;
flex-direction: row;
width: 85%;
}
.navbar .nav li {
flex: 1;
}
.navbar .nav li a {
font-weight: bold;
text-align: center;
flex: 1;
}
html:
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
{% block header %}
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="/">MySite</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<!-- <li><a href="/submit">Submit</a></li> -->
<li><a href="/vendors">Vendors</a></li>
<li><a href="/news">News</a></li>
<li><a href="/about">About</a></li>
<form class="navbar-form navbar-left" action="/action_page.php">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
</ul>
</div><!--/.nav-collapse -->
{% endblock %}
</div>
</nav>
结果: