Search code examples
htmltwitter-bootstrapcentering

How to centralize the items in bootstrap fixed navigation bar?


In the floowing code, I have tried to set float:noneand centralizing techniques to push the items to the center of the navigation, but none has worked.

How can I have the items sit in the middle of the navigation bar?

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Page 1</a></li>
      <li><a href="#">Page 2</a></li>
      <li><a href="#">Page 3</a></li>
    </ul>
  </div>
</nav>


Solution

  • You could do something like this:

    .container-fluid{
      text-align: center;
    }
    .navbar .navbar-nav {
      display: inline-block;
      float: none;
    }
    

    This will center the items of your navigation. If you want to try this out, check this JS Fiddle here.