css - How to center text inside a li element inside an unordered list -


this list working great me text within <li> elements not centering.

the <li>s must auto resize content.

#nav-menu {      font-family: verdana, arial, helvetica, sans-serif;      height: 30px;      background-image: url(../img/menu_bg.png);      background-repeat: repeat-x;      border-bottom: dotted thin #666666;      border-top: dotted thin #666666;      text-align: center;      width: 800px;  }    #nav-menu ul {      list-style: none;      padding: 0;      margin: auto 0;  }    #nav-menu li {      float: left;      border-right: dotted thin #666666;      list-style: none;      padding: 0.5em 2em 0.5em 0.75em;  }    #nav-menu li {      line-height: 1.5em;      color: #333333;      text-decoration: none;      font-size: 12px;      font-weight: bold;      display: block;  }
<div id="nav-menu">      <ul>          <li class="current_page_item"><a href="#" title="home">home</a>          <li class="current_page_item"><a href="#" title="home">home</a>          <li class="current_page_item"><a href="#" title="home">home</a>          <li class="current_page_item"><a href="#" title="home">zxczczxczhome</a>      </ul>  </div>

while you're assigning unequal padding values left , right of li (0.75em , 2em respectively) text can't centred since you're forcing off-centre padding.

if amend padding to: padding: 0.5em 1em; (0.5em top , bottom, 1em left , right) can centred.

#nav-menu {      font-family: verdana, arial, helvetica, sans-serif;      height: 30px;      background-image: url(../img/menu_bg.png);      background-repeat: repeat-x;      border-bottom: dotted thin #666666;      border-top: dotted thin #666666;      text-align: center;      width: 800px;  }    #nav-menu ul {      list-style: none;      padding: 0;      margin: auto 0;  }    #nav-menu li {      float: left;      border-right: dotted thin #666666;      list-style: none;      padding: 0.5em 1em;  }    #nav-menu li {      line-height: 1.5em;      color: #333333;      text-decoration: none;      font-size: 12px;      font-weight: bold;      display: block;  }
<div id="nav-menu">      <ul>          <li class="current_page_item"><a href="#" title="home">home</a></li>          <li class="current_page_item"><a href="#" title="home">home</a></li>          <li class="current_page_item"><a href="#" title="home">home</a></li>          <li class="current_page_item"><a href="#" title="home">zxczczxczhome</a></li>      </ul>  </div>

jsfiddle demo of above.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -