Joe Bauer
Joe Bauer

Reputation: 622

Center-align <li> in vertical <ul>

I've been trying to work this out for hours now, so here goes:

I want my li items to be centered within the ul. For some reason they seem to be aligned right. ie. I want the red dashed box to be centered within the green solid one.

I've tried margin: 0 auto;, text-align:center, etc. with no luck.

Can someone please tell me why this isn't working?

JSFiddle

The code:

.leftbar {
    position: fixed;
    width: 200px;
  }

  #navMenu {        
    margin-top: 30px;
    border: 1px solid blue;
  }

  #navList {
    text-align:center;
    border: 1px solid green;
  }

  #navList li {
    border: 1px dashed red;
  }


</style>

<div class="leftbar">
  <img src="http://goo.gl/kBrNqn">
  <div id="navMenu">
    <ul id="navList">
      <li>HOME</li>
      <li>People</li>
      <li>Places</li>
      <li>Things</li>
      <li>BLOG</li>
      <br/>
      <li>Contact</li>
    </ul>
  </div>
</div>

Upvotes: 0

Views: 93

Answers (1)

Joffrey Maheo
Joffrey Maheo

Reputation: 2919

Use reset css file (for more optimization) or you can add this in your css :

CSS :

*{
    margin:0;
    padding:0;
}

DEMO : http://jsfiddle.net/rzgn0fLL/1/

Upvotes: 3

Related Questions