overflow:hidden + display:inline-block moves text upwards

HtmlCss

Html Problem Overview


I have following HTML:

<div>
    a<span style="overflow: hidden; display: inline-block;">b</span>c
</div>

What I expect to see: abc.

What I see (in Chrome, Safari, Firefox): abc

b is higher than a and c. Why it is so and how to fix it?

Html Solutions


Solution 1 - Html

This happens because the inline-block element has height equal to its parent and overflow: hidden causes its bottom edge to be aligned on the text baseline of the parent. As a result the space that is available for descenders on the text is essentially doubled for the <span> (JSFiddle).

You can fix this by also giving it vertical-align: bottom.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniilView Question on Stackoverflow
Solution 1 - HtmlJonView Answer on Stackoverflow