Skip to content

Instantly share code, notes, and snippets.

@illnino
Forked from chriscoyier/dabblet.css
Created April 28, 2012 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save illnino/2516449 to your computer and use it in GitHub Desktop.
Save illnino/2516449 to your computer and use it in GitHub Desktop.
No space between inline-block
body {
font-family: sans-serif;
}
ul {
list-style: none
}
a{
text-decoration: none;
color:white;
}
li {
background: slategrey;
display: inline-block;
/* inline block hack for IE 6&7 */
zoom: 1;
*display: inline;
padding: 4px;
color: white
}
ul.white-space-fix li {
margin-right: -4px;
}
ul.zero-size {
font-size: 0px;
}
ul.zero-size li {
font-size: 16px;
}
<h1>Inline-block / white-space bug</h1>
original...
<ul>
<li><a href="x">one</a></li>
<li>two</li>
<li>three</li>
</ul>
fixed by funky code formatting...
<ul>
<li>
<a href="x">one</a></li><li>
two</li><li>
three</li>
</ul>
fixed by adding html comments...
<ul>
<li><a href="x">one</a></li><!--
--><li>two</li><!--
--><li>three</li>
</ul>
fixed by CSS margin-right: -4px; (breaks in IE6&7)...
<ul class="white-space-fix">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
fixed by omitting the &lt;/li&gt;
<ul>
<li>one
<li>two
<li>three
</ul>
fixed with font-size: 0 via: http://twitter.com/#!/garand/status/183253526313566208
<br><br>
<ul class="zero-size">
<li>one</li>
<li>two</li>
<li>three</li>/
<ul>
{"view":"split","fontsize":"80","seethrough":"","prefixfree":"","page":"all"}
@dangleraction
Copy link

Just one correction: Instead of

ul.white-space-fix li {
margin-right: -4px;
}

Use '-0.31em' to ensure the negative margin doesn't change when the view port is able to zoom:

ul.white-space-fix li {
margin-right: -.31em;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment