2

Possible Duplicate:
Unwanted margin in inline-block list items
How to remove “Invisible space” from HTML

I have an <ul> with multiple <li> children.

The li's just contain an image, and I removed all the margin from them. I also called display:inline-block; on them, so they are now displayed in one line.

However, there is still a small margin on the right side of the lis. I found out that it's the line break, and that, if I remove it the margin disappear. However, it's very unreadable if I have to remove all the line breaks.

Can you give me a solution for this one?


HTML

<ul>

    <li><a href="#"><img src="image1.png" alt="post_heart" /></a></li>
    <li><a href="#"><img src="image2.png" alt="post_repeat" /></a></li>
    <li><a href="#"><img src="image3.png" alt="post_tag" /></a></li>
    <li><a href="#"><img src="image4.png" alt="post_share" /></a></li>

</ul>

LESS

ul {
    display:inline;
    padding:none;
    margin:none;

    li {
        display:inline-block;

        padding:none;
        margin:none;

        a {
            display:block;  
            margin:none;
            border-right: 1px solid #e0e1e2;

            &:hover {
                .linearGradient(transparent, rgba(0,0,0,0.05));
            }
        }

        &:last-child {
            a {
                border:none;
            }
        }
    }
}
Community
  • 1
  • 1
IluTov
  • 6,807
  • 6
  • 41
  • 103

3 Answers3

4

The "margin" is actually whitespace (some combination of tabs, spaces, or newlines). You can keep your formatting by commenting it out.

<ul><!--
    --><li><img /></li><!--
    --><li><img /></li><!--
    --><li><img /></li><!--
    --><li><img /></li><!--
    --><li><img /></li><!--
--></ul>

See also: http://css-tricks.com/fighting-the-space-between-inline-block-elements/

cimmanon
  • 67,211
  • 17
  • 165
  • 171
2

Make sure you have no margin on the li's.

I've also ran into the this issue using inline-block, that in your markup, you can't have any white space between li elements or it will render it. Looks ugly, but worked.

E.g This

<ul>
<li></li><li></li><li></li><li></li><li></li><li></li>
</u>

instead of this

<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
Christopher Marshall
  • 10,678
  • 10
  • 55
  • 94
0

Just make them float:left. When they are display:inline there is always a space about 3px I think.