This is not caused by whitespace (you don't have any inside the div
s in your HTML), nor by putting inline-block
inside of another inline-block
. This is caused because of the line-height
of the outer div
. As you can see from the below fiddle, the current line-height
of the red-border div has a line-height
that is being set by the browser (and it varies from browser to browser), and as long as there is something inside of the div
that takes up space as an inline
or inline-block
item, the height
will be affected by the line-height
.
There are many ways around this, and they all pretty much do the same thing:
1) Take the inside element out of flow, and then reinsert it back in. This will make the outer div
think that there is nothing inside of it, and try to become as small as possible, and then fill up space exactly around the element when it inserted back in. The easiest way to do this is by float
ing it.
2) Make the outer element take up no space. This will make the inside element define the height
and width
of its parent. If you do font-size: 0
, as mentioned before, this will make the outer element think that the inline inside element takes up no space, and therefore not take up any space itself, and wrap itself tightly around the inner element. This can be done by setting line-height: 0
as well (which is a perfect fix for the problem, as the problem is line-height
).
There are other ways to make the parent element not have its line-height
, but that should get you started.
http://jsfiddle.net/C6V3S/4/
inline-flex
,inline-table
, see if those work – markasoftwareinline-flex
– markasoftware