vertical-align, inline-blocks and line-height
In the following test cases, six inline-blocks (colored rectangles) are vertically positioned with the following values for vertical-align:
- top
- bottom
- baseline
- middle
- text-top
- text-bottom
First case, line-height: 2
gQfxÈ
Second case, line-height: normal
gQfxÈ
Third case, line-height: 0.5
gQfxÈ
Fourth case, line-height: 0.5, without text-top, text-bottom
gQfxÈ
Fifth case, line-height: 0.5, without top, bottom, ...
gQfxÈ
Sixth case, line-height: 0.5, without inline-blocks
gQfxÈ
Notes:
- The red and blue inline-blocks (top and bottom vertical-align) should always touch the box horizontal borders.
- In IE6- all cases with inline-blocks are rendered the same, i.e. the line-height is not honored (it is always rendered as 'normal'.) See IE Line-height / Replaced Element Bug, IE6-/Win line-height problem with images.
- In IE7 the above problem is partially fixed, but still occurs when the specified line-height is less than normal (cases 4, 5.)
- In IE7 the red and blue inline-blocks are always positioned (relatively to the text) in the same place as in the case with line-height normal (case 2), i.e. they seem not to see a changed line-height (case 1.)
- In all IE7-/Win the green inline-blocks (vertical-align: middle) are nicely in the vertical middle of the parent box. Unfortunately this is not what the specs say, sigh! (CSS2.1 10.8.1: middle = "Align the vertical midpoint of the box with the baseline of the parent box plus half the x-height of the parent".) The difference is more noticeable with some font-family, see this same page vertical-align of images and line-height with different fonts.
Related tests:
- vertical-align of tall images,
- an image in a box,
- an image in a box with different line heights,
- the same cases of this page, but with a margin-bottom on the inline-blocks vertical-align, inline-blocks, margins and line-height,
- the same cases of this page, but with images instead of inline-blocks vertical-align, images and line-height,
- IE7-/Win line-height problem with inline images.
CSS tests home