I'm building my first website with HTML5, and have run into a problem that is driving me insane. I'm trying to perfectly center the items within a horizontal navigation bar at the top of my page. The items are within an unordered list.
I have display:inline-block
applied to the list items with text-align:center
on the parent. It seems to want to work, but it appears just to the right of the center. I tried taking everything out of a list and simply putting it into a div, and it immediately worked and centered perfectly, but I could not figure out how to efficiently format the individual elements without having them in a list. As soon as I put them back into a list, they shifted back over to the right. I have put a white background on the header to make it easier to see the alignment.
#menu {
width: 960px;
max-height: 90px;
background: #ffffff;
}
#menu ul {
text-align: center;
list-style: none;
padding-top: 18px;
width: 960px;
}
#menu li {
display: inline-block;
vertical-align: middle;
}
#menu li a,
menu li a:visited {
color: #333347;
text-decoration: none;
font-size: 20px;
font-weight: bold;
padding: 0px 13px 0px 13px;
}
<nav id="menu">
<ul>
<li class="menuitem"><a href="index.html">Home</a></li>
<li class="menuitem"><a href="gallery.html">Gallery</a></li>
<li class="menuitem"><a href="shop.html">Shop</a></li>
<li class="menuitem"><a href="contact.html">Contact</a></li>
</ul>
</nav>
I expected it to center the list, but it appears slightly to the right of the center.