问题
trying to get a bootstrap navbar to have links on the left, center and right side on a responsive website.
is this even possible? maybe navbar-justified is wrong to center content on the navbar?
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<ul class="nav navbar-nav navbar-left">
<a class="navbar-brand" href="#home"> LEFT </a>
</ul>
<ul class="nav navbar-nav navbar-justified">
<a href="#"> CENTER </a>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#facebook"> <img src="fb.png" class="fb"> RIGHT </a>
</li>
</ul>
</div>
</nav>
回答1:
You can use the the navbar-left/navar-right
classes to position your links and a custom class to position the navbar-brand
according to the size you need it to be. See working example Snippet.
.navbar-custom .navbar-brand.navbar-brand-centered {
position: absolute;
left: 50%;
display: block;
width: 200px;
text-align: center;
top: 0;
}
.navbar.navbar-custom > .container .navbar-brand.navbar-brand-centered,
.navbar.navbar-custom > .container-fluid .navbar-brand.navbar-brand-centered {
margin-left: -100px;
}
<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-default navbar-custom" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#js-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>
</div> <a class="navbar-brand navbar-brand-centered" href="#/">Brand</a>
<div class="collapse navbar-collapse" id="js-navbar-collapse">
<ul class="nav navbar-nav navbar-left">
<li><a href="#/">Link</a>
</li>
<li><a href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a>
</li>
<li><a href="#">Link</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="well">Yup</div>
</div>
来源:https://stackoverflow.com/questions/33226509/left-right-centering-content-inside-a-bootstrap-navbar