Inline blocks have this weird space in-between them. I could live with it, up to a point where, if I load more content with an AJAX call, the tiny space goes away. I know I'm missing something here.
div { width: 100px; height: auto; border: 1px solid red; outline: 1px solid blue; margin: 0; padding: 0; display: inline-block; }
http://jsfiddle.net/AWMMT/
How to make the spacing consistent in Inline blocks?
“display: inline-block” Property: This property is used to display an element as an inline-level block container. The element itself is formatted as an inline element, but it can apply height and width values. It is placed as an inline element (on the same line as adjacent content).
Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.
HTML Break (<br>) Tag If you want to prevent a line break between two words, use a non-breaking space. If you want to insert a line break, use the HTML break tag, written as <br>.
The space is in the HTML. There are several possible solutions. From best to worst:
float: left
instead of display: inline-block
, but this has undesirable effects on t he height: http://jsfiddle.net/AWMMT/3/ font-size
to 0 and set an appropriate font-size
for the internal elements: http://jsfiddle.net/AWMMT/4/ -- this is pretty simple, but then you can't take advantage of relative font size rules on the internal elements (percentages, em)http://jsfiddle.net/AWMMT/1/
<div>...</div><div>...</div> ^ |--- no whitespace/new line here.
Your spaces were the new lines the browser converted to "spaces" when displaying it.
Or you could try to hack a bit with CSS:
A flexbox conveniently ignores whitespace between its child elements and will display similarly to consecutive inline-block elements.
http://jsfiddle.net/AWMMT/470/
body { display: flex; flex-wrap: wrap; align-items: end; }
Old answer (still applies to older, pre-flexbox browsers) http://jsfiddle.net/AWMMT/6/
body { white-space: -0.125em; } body > * { white-space: 0; /* reset to default */ }
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