Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overflow:hidden + display:inline-block moves text upwards [duplicate]

Tags:

html

css

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?

like image 822
Daniil Avatar asked Dec 13 '13 12:12

Daniil


People also ask

What does inline-block display do?

“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).

What is the use of overflow hidden?

overflow: hidden With the hidden value, the overflow is clipped, and the rest of the content is hidden: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.

What is the opposite of display inline-block?

opposite of display block is. display : none; it used for deleting and recreating them. You can also consider inline-block : inline-block elements inline elements but they have a width and a height.

What is the opposite of overflow hidden?

The opposite of the default visible is hidden. This literally hides any content that extends beyond the box. This is particularly useful in use with dynamic content and the possibility of an overflow causing serious layout problems.


1 Answers

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.

like image 95
Jon Avatar answered Oct 21 '22 00:10

Jon