0

trying to get a bootstrap navbar to have links on the left, center and right side on a responsive website.

is this even possible? maybe navbar-justified is wrong to center content on the navbar?

 <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <ul class="nav navbar-nav navbar-left">
            <a class="navbar-brand" href="#home"> LEFT </a>
          </ul>
          <ul class="nav navbar-nav navbar-justified">
            <a href="#"> CENTER </a>
          </ul>
          <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="#facebook"> <img src="fb.png" class="fb"> RIGHT </a>
          </li>
        </ul>
      </div>
    </nav>
Ben Casalino
  • 2,262
  • 5
  • 20
  • 28
  • also tried adding to align="center" to a div, ul and li and that didnt work. but maybe that is a better way to go about centering the content? – Ben Casalino Oct 20 '15 at 01:36

1 Answers1

2

You can use the the navbar-left/navar-right classes to position your links and a custom class to position the navbar-brand according to the size you need it to be. See working example Snippet.

.navbar-custom .navbar-brand.navbar-brand-centered {
  position: absolute;
  left: 50%;
  display: block;
  width: 200px;
  text-align: center;
  top: 0;
}
.navbar.navbar-custom > .container .navbar-brand.navbar-brand-centered,
.navbar.navbar-custom > .container-fluid .navbar-brand.navbar-brand-centered {
  margin-left: -100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-default navbar-custom" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#js-navbar-collapse"> <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>

      </button>
    </div> <a class="navbar-brand navbar-brand-centered" href="#/">Brand</a>

    <div class="collapse navbar-collapse" id="js-navbar-collapse">
      <ul class="nav navbar-nav navbar-left">
        <li><a href="#/">Link</a>

        </li>
        <li><a href="#">Link</a>

        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a>

        </li>
        <li><a href="#">Link</a>

        </li>
      </ul>
    </div>
  </div>
</div>
<div class="container">
  <div class="well">Yup</div>
</div>
vanburen
  • 21,502
  • 7
  • 28
  • 41
  • 1
    You're welcome and please mark your question as an answered if the solution worked then others can benefit from it. – vanburen Oct 20 '15 at 10:38
  • well, I just got around to trying it today and i created a project with literally nothing else in it other than this code, and it seemed to not center the content, which is weird because it works in the snippet provided. – Ben Casalino Oct 20 '15 at 22:58
  • 1
    The only areas that come to mind are that I use custom classes as to not directly overwrite the framework (in the example a generic .navbar-custom and .navbar-brand-centered) and the other is the size of the navbar-brand-centered may need adjusting depending on how long the text is. Let me know though. – vanburen Oct 20 '15 at 23:04
  • my other question is ng-href is for angular I thought? maybe it wont work unless i enable angular, ill give it a try! thanks! – Ben Casalino Oct 20 '15 at 23:06
  • your css is a little confusing, not sure why you would even need.... left: 50%; or width: 200px; – Ben Casalino Oct 20 '15 at 23:08
  • No you're correct and that's my fault completely, that is angular but it wouldn't cause anything to not work in this instance. You won't need that unless you're using AngularJS. Sorry! – vanburen Oct 20 '15 at 23:08
  • no worries, i appreciate your help! i actually just figured it out with this link http://stackoverflow.com/questions/19733447/bootstrap-navbar-with-left-center-and-right-aligned-items – Ben Casalino Oct 20 '15 at 23:14
  • No problem and glad to help! – vanburen Oct 20 '15 at 23:17