I’m running into a weird issue that I’ve never noticed before. I have the following code:
<div class="feedback">
<span> Was this helpful?</span>
<ul>
<li>
<a href="#">Yes</a>
</li>
<li>
<a href="#">No</a>
</li>
<li>
<a href="#">No</a>
</li>
</ul>
</div>
Very simple block of code. Ignore the second no, as it’s literally only there to give me a third li to help me figure this out. Now, here’s the CSS…
div.feedback {
position: relative;
}
span {
float: left;
}
li {
display: inline-block;
padding: 0;
margin: 0;
border-left: 1px solid #000
}
Now, here’s what’s happening:

See the extra spacing that’s seemingly coming from nowhere? I moved to border-right just to test it, and got even more inconsistent results:

Now, the 3rd LI has 0 padding and margin, as it should. The other two still have a spare space.
Lastly, the browser comprehends the proper height and width of the li, and attributes no margin or padding to it. According to the browser, the text should be smashed up against the border, as I also expect.

Can someone please explain what this extra 3-5 pixels of spacing is on the right of the text?
That’s because linebreaks are treated as a space in HTML. You’ve specified your inner elements to be
inline-block, which means that spaces between them are displayed.You can either:
<li>,<li>s.A third (lesser) option exists, it’s the use of
float.floatwas originally meant to allow for elements to be pushed to the edges of the container, while having text flowing around it freely (like images in a newspaper). That feature wasexploitedused for layout as well, when people discovered it would make block level elements stack horizontally.Using
floatwould mean you need toclearafter yourself, by either using a clearfix, or having an element withclear: bothset on it.This option is lesser, because much like tabular layouts, it’s not the original purpose of
float, implementation may differ between browsers and between time periods, but most importantly, it adds the overhead issues of clearing. (So stick withdisplay: inline-blockif you can help it!)