I have a UL with LIs that will be displayed horizontally using display:inline-block. However, these collapse all whitespace (including newlines and tabs) to a single space between the elements, when I require they be perfectly flush for measurement purposes; I don't want my measurements thrown off by varying sizes of spaces among fonts.
Is there any way to remove whitespace from between these?
I need this done without having control of the HTML; this will be for a small proof-of-concept framework that shows it can be made without abusing float
SSCCE: http://jsfiddle.net/nSsTP/
<ul>
<li>Semantic Cell 1</li>
<li>Semantic Cell 2</li>
<li>Semantic Cell 3</li>
<li>Pretty Cell 4</li><li>Pretty Cell 5</li><li>Pretty Cell 6</li>
</ul>
<style>
ul>li{
background: gray;
display: inline-block;
}
</style>
You can use one more style tag for
ul
{
font-size: 0;
}
OR
ul>li
{
display: inline-block;
background: gray;
float:left;
}
Hope this will really help.
inline-block leaves white-space between elements.
To remove this space, write elements on same line.
Change
<ul>
<li>Semantic Cell 1</li>
<li>Semantic Cell 2</li>
<li>Semantic Cell 3</li>
<li>Pretty Cell 4</li><li>Pretty Cell 5</li><li>Pretty Cell 6</li>
</ul>
to
<ul>
<li>Semantic Cell 1</li><li>Semantic Cell 2</li><li>Semantic Cell 3</li><li>Pretty Cell 4</li><li>Pretty Cell 5</li><li>Pretty Cell 6</li>
</ul>
Demo here.
OR:
Pure css solution:
ul{font-size:0;}
li{font-size:1rem;}
Demo here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With