Skip to content

Instantly share code, notes, and snippets.

@rosemarydotworld
Created November 20, 2014 00:36
Show Gist options
  • Save rosemarydotworld/996930a42065c407094b to your computer and use it in GitHub Desktop.
Save rosemarydotworld/996930a42065c407094b to your computer and use it in GitHub Desktop.
Inline-block elements without spaces in pure HTML

Problem: Elements set to display: inline-block will render with spaces between them if there's whitespace in the source, which makes formatting difficult. You can fix this by putting font-size: 0 on the parent, but it feels pretty hacky.

<!-- Looks good, renders with spaces -->
<ul>
<li class="inline-block"></li>
<li class="inline-block"></li>
<li class="inline-block"></li>
</ul>
<!-- Looks crappy, renders without spaces -->
<ul><li class="inline-block"></li><li class="inline-block"></li><li class="inline-block"></li></ul>
<!-- Looks pretty good, renders without spaces -->
<ul>
<li class="inline-block"></li><!--
--><li class="inline-block"></li><!--
--><li class="inline-block"></li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment