I'm using twitter bootstrap to create togglable tabs. Here is the css I'm using:
<div class="container"> <ul class="nav nav-tabs"> <li><a href="#home" data-toggle="tab">Home</a></li> <li><a href="#profile" data-toggle="tab">Profile</a></li> <li><a href="#messages" data-toggle="tab">Messages</a></li> <li><a href="#settings" data-toggle="tab">Settings</a></li> </ul> </div>
This html displays the tabs correctly, but pulled to the left (which is what is supposed to happen). I've tried tinkering with the CSS to get the tabs to center on the page, but no luck yet. I thought someone with more css experience would know how to do this.
As a note, there is another question about centering nav pills, which I tried, but it didn't work with just plain nav tabs.
Thanks.
Use the . nav-justified class in Bootstrap to center tabs in Bootstrap.
Center tabs inhabit one-line paragraphs. Click the Tab gizmo on the ruler until the center tab stop shows up. The Center Tab Stop icon is shown in the margin. Click the ruler to set the center tab stop's position.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With