Answered
Lately, I feel like I'm starting to lose my mind... I am currently working on setting up a basic top navigation that is centered in the header with margin-0-auto. It consists of five <li>
elements, each with a width of 200px. Simple math tells me that adds up to 1000px in total width. However, the parent <ul>
element needs to be set at 1016px width to contain all the children. I can't figure out why this discrepancy exists, especially since I have removed all margins and paddings using a CSS reset.
Here's the code snippet:
HTML
<div id="header-wrapper">
<div id="header">
<ul id="head-menu">
<li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a></li>
<li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a></li>
<li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a></li>
<li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a></li>
<li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a></li>
</ul>
</div>
</div>
CSS
#header-wrapper { width: 100%; height: 56px; position: relative }
#header { width: 100%; height: 56px; background: #111; position: absolute; }
#head-menu { width: calc(5*200px); margin: 0 auto;}
.head-menu-item { display: inline-block }
.head-menu-item-link { display: inline-block; padding: 20px; width: calc(200px - 40px); text-align: center }
Update 29.09.13
In case anyone else is facing the same issue, instead of removing white spaces or adjusting negative left-margins, I found an easy solution:
</li><li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a>
</li><li class="head-menu-item"><a href="" class="head-menu-item-link">Navlink</a>
This method worked smoothly without making major changes to the code while maintaining its cleanliness.