Reputation: 29
I'm trying to center my navigation items, what do I need to edit in order to do so? I've looked in the bootstrap.css file and can't find where to change the settings. I can't figure out how to do it I've been trying everything.
<div id="nav" class="navbar navbar-inverse navbar-static-top">
<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="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Forum</a></li>
<li><a href="#">Download</a></li>
<li><a href="#">Play Now</a></li>
<li><a href="http://www.07-pk.com/forum/register.php">Register</a></li>
<li class="dropdown">
<a class="dropdown-toggle" id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="/page.html">
Login
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<!-- login form -->
<form action="http://www.07-pk.com/forum/login.php" method="post" onsubmit="md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf)">
<script type="text/javascript" src="http://www.07-pk.com/forum/clientscript/vbulletin_md5.js"></script>
Username: <input type="text" class="button" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="1" value="Username" onfocus="if (this.value == 'Username') this.value = '';" />
<br />
Password: <input type="password" class="button" name="vb_login_password" size="10" accesskey="p" tabindex="2" />
<input type="submit" class="button" value="Login" tabindex="4" title="" accesskey="s" />
<input type="hidden" name="s" value="" />
<input type="hidden" name="do" value="login" />
<input type="hidden" name="forceredirect" value="1" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
<input type="hidden" name="url" value="http://www.07-pk.com" />
</form>
<!-- / login form -->
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
Upvotes: 2
Views: 4971
Reputation: 714
Brandon Himpfen give an example of this on his blog. http://www.himpfen.com/center-align-bootstrap-nav-pills/ "In Twitter Bootstrap there are navigation (nav) pills and by default, it is left aligned. We can wrap the navigation with a HTML div element and add a bit of CSS."
http://www.bootply.com/AiyCfTCcBV
/* CSS used here will be applied after bootstrap.css */
.centered-pills {
text-align: center;
}
.centered-pills ul.nav-pills {
display: inline-block;
}
.centered-pills li {
display: inline;
}
.centered-pills a {
float: left;
}
* html .centered-pills ul.nav-pills, *+html .centered-pills ul.nav-pills {
display: inline;
}
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<a class="navbar-brand pull-left" href="#">Brand</a>
<div class="centered-pills">
<ul class="nav nav-pills">
<li><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Messages</a></li>
</ul>
<a class="navbar-brand pull-right" href="#">Brand</a>
</div>
</div>
</nav>
Upvotes: 0
Reputation: 4512
Wrap your objects you want to center with this <div>
<div style="width:300px; margin: 0 auto;">
//your code here
</div>
Upvotes: 0
Reputation: 8715
Twitter Bootstrap navigation items are having float: left
by default. Consider adding the following styles to your own CSS file (or modify the bootstrap.css, which I would not recommend):
.navbar .nav li {
width: 100px; /* or whatever width you want for items */
display: inline-block;
float: none;
}
.navbar .nav {
float: none;
text-align: center;
}
Upvotes: 7