<div class="wrap">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li><br>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
css
.wrap {
display:table;
background: green;
padding: 10px 20px;
}
ul {
display:table;
background: yellow;
margin: 0;
padding: 0;
font-size: 0;
}
li {
margin:0 4px 4px 0;
display: inline-block;
width: 70px;
height: 50px;
background: purple;
list-style: none;
}
li:nth-child(7){
margin-right: 0px;
}
******************************************************************
other
<div class="wrap">
<ul>
<li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li>
</ul>
</div>
also
<div class="wrap">
<ul>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
</ul>
</div>
css
.wrap {
background: green;
width: 520px;
padding: 10px 20px;
}
ul {
background: yellow;
margin: 0;
padding: 0;
border:0;
}
li {
position:relative;
display: inline-block;
width: 70px;
height: 50px;
background: purple;
list-style: none;
margin-right: 5px;
}
li:nth-child(7){
margin-right: 0px;
}
li:nth-child(14){
margin-right: 0px;
}
This isn't a "bug" (I don't think). It's just the way setting elements on a line works. You want spaces between words that you type to be spaces right? The spaces between these blocks are just like spaces between words. That's not to say the spec couldn't be updated to say that spaces between inline-block elements should be nothing, but I'm fairly certain that is a huge can of worms that is unlikely to ever happen.
Here's some ways to fight the gap and get inline-block elements sitting directly next to each other.
Remove the spaces
The reason you get the spaces is because, well, you have spaces between the elements (a line break and a few tabs counts as a space, just to be clear). Minimized HTML will solve this problem, or one of these tricks:
<ul>
<li>
one</li><li>
two</li><li>
three</li>
</ul>
or
<ul>
<li>one</li
><li>two</li
><li>three</li>
</ul
or with comments...
<ul>
<li>one</li><!--
--><li>two</li><!--
--><li>three</li>
</ul>
They're all pretty funky, but it does the trick.
Negative margin
You can scoot the elements back into place with negative 4px of margin (may need to be adjusted based on font size of parent). Apparently this is problematic in older IE (6 & 7), but if you don't care about those browsers at least you can keep the code formatting clean.
display: inline-block;
margin-right: -4px;
Skip the closing tag
HTML5 doesn't care anyway. Although you gotta admit, it feels weird.
<ul>
<li>one
<li>two
<li>three
</ul>
to the- items, how do you intend to define that line break occurs right after the sixth
- ? if they all have display: inline-block; AND
– LGVentura May 27 '14 at 22:06IS WHITE-SPACE:NORMAL;?