Center the Nav in Twitter Bootstrap

Center the nav in Twitter Bootstrap

Possible duplicate of Modify twitter bootstrap navbar.
I guess this is what you are looking for (copied):

.navbar .nav,
.navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}

.navbar-inner {
text-align:center;
}

As stated in the linked answer, you should make a new class with these properties and add it to the nav div.

How can I center Twitter-Bootstrap 3 navbar links?

Bootstrap 3 has a nav-justified class that can be used on nav. No extra CSS required:

<div class="container">
<h3 class="text-muted">Project name</h3>
<ul class="nav nav-justified">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>

Demo: http://bootply.com/72519


Based on the comments, to have full-width centered links using the navbar-nav class, use flexbox...

.navbar-center {
width:100%;
display: flex;
}
.navbar-center>li {
flex:1 1 auto;
}

<div class="navbar navbar-default">
<div class="container">
<ul class="nav navbar-nav navbar-center text-center">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">More</a></li>
<li><a href="#">Options</a></li>
</ul>
</div>
</div>

https://www.codeply.com/go/6ZE3obnpuP


Also see
Bootstrap NavBar with left, center or right aligned items

Center Navbar in Bootstrap

How do i shift the text in twitter bootstrap navbar to center?

Depending on where you want the Brand link to appear, here are two possiblities
http://jsfiddle.net/panchroma/cW9sA/

or

http://jsfiddle.net/panchroma/GWMnF/

EDIT: A third variation where the iPolice brand link is always centered, even at narrow viewports

http://jsfiddle.net/panchroma/F5x5Z/

Note that in the second example I've added a copy of the brand link into the main menu, and used the utility classes of .hidden-desktop and .visible-desktop to fine tune how this is displayed at different viewports

Important CSS is

#twitterbootstrap .navbar .nav,
#twitterbootstrap .navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}

#twitterbootstrap .navbar-inner {
text-align:center;
}

Some of this CSS is based on an answer from Andres Ilich

Good luck!

Twitter Bootstrap 3.0 Logo in the center of navbar

This has been asked before a few times, like here.

I've set up a jsfiddle similar to your HTML provided, using your Gravatar since your logo wasn't available: http://jsfiddle.net/q68VS/

Important CSS:

.nav-center {
margin:0;
float:none;
}

.navbar-inner{
text-align:center;
}

Twitter Bootstrap - center navbar when responsive to two rows

If you want to keep menu in center avoid using float. Check if this helps you.

@media (min-width: 768px) {
.navbar-nav>li {
float: none;
display: inline-block;
}
}

How do I center the twitter bootstrap tabs on the page?

nav-tabs list items are automatically floated to the left by the bootstrap so you have to reset that and instead display them as inline-block, and to center menu items we have to add the attribute of text-align:center to the container, like so:

CSS

.nav-tabs > li, .nav-pills > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
zoom:1; /* hasLayout ie7 trigger */
}

.nav-tabs, .nav-pills {
text-align:center;
}

Demo: http://jsfiddle.net/U8HGz/2/show/
Edit here: http://jsfiddle.net/U8HGz/2/


Edit: patched version that works in IE7+ provided by user @My Head Hurts down in the comments below.

Demo: http://jsfiddle.net/U8HGz/3/show/
Edit here: http://jsfiddle.net/U8HGz/3/

Center an element in Bootstrap Navbar

In Bootstrap 4, there is a new utility known as .mx-auto. You just need to specify the width of the centered element.

Ref: http://v4-alpha.getbootstrap.com/utilities/spacing/#horizontal-centering

Diffferent from Bass Jobsen's answer, which is a relative center to the elements on both ends, the following example is absolute centered.

Here's the HTML:

<nav class="navbar bg-faded">
<div class="container">
<ul class="nav navbar-nav pull-sm-left">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 4</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-logo mx-auto">
<li class="nav-item">
<a class="nav-link" href="#">Brand</a>
</li>
</ul>
<ul class="nav navbar-nav pull-sm-right">
<li class="nav-item">
<a class="nav-link" href="#">Link 5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 6</a>
</li>
</ul>
</div>
</nav>

And CSS:

.navbar-logo {
width: 90px;
}


Related Topics



Leave a reply



Submit