I'm having a problem with bootstrap 3 navigation, i have some content on the left, center and right. it seems there is no option for centering the navigation.
http://jsfiddle.net/29tQt/embedded/result/
I'm trying to get the links titled "center" to be in the center of the page, how can i achieve that ?
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<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 class="active"><a href="#">Center</a>
</li>
<li><a href="#">Center</a>
</li>
<li><a href="#">Center</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Right</a>
</li>
<li><a href="#">Right</a>
</li>
</ul>
</div>
</div>
</nav>
This question is related to
css
twitter-bootstrap
twitter-bootstrap-3
Try this css
.clearfix:before, .clearfix:after, .container:before, .container:after, .container-fluid:before, .container-fluid:after, .row:before, .row:after, .form-horizontal .form-group:before, .form-horizontal .form-group:after, .btn-toolbar:before, .btn-toolbar:after, .btn-group-vertical > .btn-group:before, .btn-group-vertical > .btn-group:after, .nav:before, .nav:after, .navbar:before, .navbar:after, .navbar-header:before, .navbar-header:after, .navbar-collapse:before, .navbar-collapse:after, .pager:before, .pager:after, .panel-body:before, .panel-body:after, .modal-footer:before, .modal-footer:after {
content: " ";
display: table-cell;
}
ul.nav {
float: none;
margin-bottom: 0;
margin-left: auto;
margin-right: auto;
margin-top: 0;
width: 240px;
}
Add 'justified' class to 'ul'.
<ul class="nav navbar-nav justified">
CSS:
.justified {
position:absolute;
left:50%;
}
Now, calculate its 'margin-left' in order to align it to center
.
// calculating margin-left to align it to center;
var width = $('.justified').width();
$('.justified').css('margin-left', '-' + (width / 2)+'px');
.navbar-nav {
float: left;
margin: 0;
margin-left: 40%;
}
.navbar-nav.navbar-right:last-child {
margin-right: -15px;
margin-left: 0;
}
Since You Have used the float
property we don't have many options except to adjust it manually.
Source: Stackoverflow.com