1

I am trying to align my navbar items centrally horizontally but they are aligned to the left.

Can someone offer some help?

This is a Desktop issue - just to be clear, I'm having this issue at desktop level.

Here is my current code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<header class="container">
  <div id="menu" class="navbar navbar-default">
      <div class="navbar-header">
          <button class="btn btn-success navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <span class="glyphicon glyphicon-chevron-down"></span>
          </button>
      <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
              <li class="nav active"><a href=".">Home</a>
              </li>
              <li class="nav"><a href="about.html">About</a>
              </li>
              <li class="nav"><a href="contact.html">Contact</a>
              </li>
          </ul>
      </div>
  </div>
</header>

Demo: https://jsfiddle.net/cjoasysz/

michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190
  • 1
    So to clarify, you want all of the items when the navbar is on a desktop width (i.e. not using the collapse button) to be placed at the center? – willwolfram18 Sep 28 '16 at 13:49
  • 1
    @Bwolfing That's right. So Home / About / Contact would be in the center of the nav area, not to the left. – michaelmcgurk Sep 28 '16 at 13:49
  • 1
    Following the logic from that answer you need to add two more rules to work on that fiddle https://jsfiddle.net/urm4xdtf/5/ – DaniP Sep 28 '16 at 13:59

2 Answers2

1

Just add this in your CSS

ul.nav li {
   text-align: center;
}

I updated your fiddle: https://jsfiddle.net/cjoasysz/1/

pleinx
  • 616
  • 3
  • 8
1

You can use the CSS to align the text to center.

.navbar-nav>li>a {
    text-align: center;
}

Demo

To center the navigation tabs you can use ..

.navbar-header {
    display: inline-block;
    float: none;
    vertical-align: middle;
}
.navbar-default {
  text-align: center;
}

Demo 2

Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88