Skip to content

Instantly share code, notes, and snippets.

@jonathanhefner
Created August 1, 2012 19:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanhefner/3229878 to your computer and use it in GitHub Desktop.
Save jonathanhefner/3229878 to your computer and use it in GitHub Desktop.
CSS-only technique to remove whitespace from between inline-block elements
<!--
Here is a CSS-only technique to remove whitespace from between inline-block
elements. Note that any text nodes that are direct children of the
containing-element will need their font-size manually readjusted.
-->
<style type="text/css">
.big-text {
font-size: 48px;
}
.normal-text {
font-size: 16px;
}
.small-text {
font-size: 10px;
}
.big-text, .normal-text, .small-text {
margin-bottom: 50px;
}
.containing-element {
background: #fdd;
}
.inline-block-element {
background: #ddf;
border: 1px solid #aaf;
border-right: 1px solid #2f2;
height: 4em;
width: 4em;
}
/**** here's the magic ****/
.containing-element {
font-size: 5%;
}
.inline-block-element {
display: inline-block;
*display: inline; zoom: 1; /* for IE */
font-size: 2000%;
margin-left: -1px;
*margin-left: 0; /* for IE */
}
</style>
<div class="big-text">
Example with big font-size
<div class="containing-element">
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
</div>
</div>
<div class="normal-text">
Example with normal font-size
<div class="containing-element">
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
</div>
</div>
<div class="small-text">
Example with small font-size
<div class="containing-element">
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
<div class="inline-block-element">&nbsp;</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment