I want to be able to center the nav dead middle of a page and have it stayed centered in different resolutions. I don't want to use offsets to push it over or margin-left as this would just screw it up in different browser widths. This is the typical bar that I am messing around with but the ul always winds up left aligned.
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#">Menu</a></li>
<li><a href="#">On Tap</a></li>
<li><a href="#">Shows</a></li>
<li><a href="#">Surfwear</a></li>
<li><a href="#" >Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!-- container -->
</div><!-- navbar-inner -->
</div><!-- navbar navbar-fixed-top -->
This question is related to
css
twitter-bootstrap
center
navbar
For Bootstrap v4 check this:
https://v4-alpha.getbootstrap.com/components/pagination/#alignment
only add class to ul.pagination:
<nav">
<ul class="pagination justify-content-center">
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
You can make the .navbar
fixed width, then set it's left and right margin to auto
.
.navbar{
width: 80%;
margin: 0 auto;
}?
Code used basic nav bootstrap
<!--MENU CENTER`enter code here` RESPONSIVE -->_x000D_
_x000D_
<div class="container-fluid">_x000D_
<div class="container logo"><h1>LOGO</h1></div>_x000D_
<nav class="navbar navbar-default menu">_x000D_
<div class="container-fluid">_x000D_
<!-- Brand and toggle get grouped for better mobile display -->_x000D_
<div class="navbar-header">_x000D_
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#defaultNavbar2"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>_x000D_
</div>_x000D_
<!-- Collect the nav links, forms, and other content for toggling -->_x000D_
<div class="collapse navbar-collapse" id="defaultNavbar2">_x000D_
<ul class="nav nav-justified" >_x000D_
<li><a href="#">Home</a></li>_x000D_
<li><a href="#">Link</a></li>_x000D_
<li><a href="#">Link</a></li>_x000D_
<li><a href="#">Link</a></li>_x000D_
<li><a href="#">Link</a></li>_x000D_
<li><a href="#">Link</a></li>_x000D_
<li><a href="#">Link</a></li>_x000D_
</ul>_x000D_
</div>_x000D_
<!-- /.navbar-collapse -->_x000D_
</div>_x000D_
<!-- /.container-fluid -->_x000D_
</nav>_x000D_
</div>_x000D_
<!-- END MENU-->
_x000D_
For anyone needing this for Bootstrap 3, it is now much easier.
The new nav-justified
class can be used to center all of the navbar links..
http://www.bootply.com/g3g125MLGr
<div class="navbar">
<ul class="nav nav-justified" id="myNav">
<li><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
Or with a little CSS you can center just the brand/logo, and keep the left/right links separate..
.navbar-right {
margin-left:auto;
margin-right:auto;
max-width :40%;
float:none !important;
}
just copy this code and change max-width
as you like
I prefer this :
<nav class="navbar">
<div class="hidden-xs hidden-sm" style="position: absolute;left: 50%;margin-left:-56px;width:112px" id="centered-div">
<!-- this element is on the center of the nav, visible only on -md and -lg -->
<a></a>
</div>
<div class="container-fluid">
<!-- ...things with your navbar... -->
<div class="visible-xs visible-sm">
<!-- this element will be hidden on -md and -lg -->
</div>
<!-- ...things with your navbar... -->
</div>
</nav>
The element is perfectly centered, and will be hidden on some screen sizes (there was no place left on -xs and -sm for me for example). I get the idea from Twitter's actual navbar
http://www.bootply.com/3iSOTAyumP in this example the button for collapse was not clickable because the .navbar-brand was in front.
http://www.bootply.com/RfnEgu45qR there is an updated version where the collapse buttons is actually clickable.
Source: Stackoverflow.com