Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display:inline-block and overflow:hidden leading to different vertical alignment

Tags:

html

The following code renders differently in different browsers (IE = FF = higher than baseline, Chrome = on baseline).

  1. Whose fault is it? Where should I file a bug report?

  2. Do you know a way how to get this solved cross-browser. If I change vertical-alignment, I get it to work in some browsers, but not the others.

<!doctype html>
<html>
<head>
    <style>
        .a {
            display: inline-block;
            overflow: hidden;
            color: red;
        }
    </style>
</head>
<body>
    baseline__<div class="a">test</div>__baseline
</body>
</html>

http://jsfiddle.net/T2vQj/

like image 650
mh543 Avatar asked Feb 14 '13 07:02

mh543


2 Answers

Yes. You need to do these:

  1. Remove the style overflow: hidden;. This is not needed here. You need this only when you give a width or text-overflow: ellipsis;.

  2. Add vertical-align: bottom;. The vertical alignment of the text will change when the display is changed from inline to inline-block.

like image 172
Praveen Kumar Purushothaman Avatar answered Oct 22 '22 07:10

Praveen Kumar Purushothaman


It seems Chrome is in error. The CSS 2.1 spec says

The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its 'overflow' property has a computed value other than 'visible', in which case the baseline is the bottom margin edge.

Since the overflow property computes to something other than 'visible' the inline-block's baseline is the bottom margin edge, which sits on the baseline of the containing line box, and therefore must raise up the contained text to allow space for the descenders of that text.

like image 25
Alohci Avatar answered Oct 22 '22 08:10

Alohci