The extra height is the same height as the height difference between vertical-align: baseline
, and vertical-align: bottom
. The "descender line". That's where the seemingly random "5 extra pixels" comes from. If the font size is 10 times as large, this gap will also be 10 times as large.
Also, it seems that when overflow: hidden
is not there, the inline-block
element has its baseline as the same baseline of its last line of text.
This leads me to believe that overflow: hidden
forces the baseline of the entire inline-block
element to be at the bottom of the element. Even though there is no text there, the parent of the inline-block
element reserves space for the descender line. In the example given in the question, it cannot be easily seen since the parent of the inline-block
element has height: 100%
. So, instead, that extra space reserved for the descender line overflows out of that parent div.
Why is this space still there, even though there's no text? I think that's because the inline-block
creates an inline formatting context, which is what causes this space. Were this element to be a block
, it would only create this inline formatting context once it encounters an inline element or text.
This is just a theory, but it seems to explain it. It also explains why @Jonny Synthetic's answer works: adding overflow: hidden to the parent hides that extra descender line.
Thanks to @Hashem Qolami for the jsbins that gave me this theory.