XML technologies / CSS / Advanced websites with CSS / CSS property reference / vertical-align
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The property vertical-align controls vertical alignment of text and other inline content, and also content inside table cells.
Inherited: no
See also: text-align
Values
These keywords align inline content relative to the parent’s font size:
baseline: Aligns the content’s baseline with the parent’s. (The baseline is the imaginary writing line supporting letter bottoms; descenders extend below it.) Content without a baseline, such as an image, aligns its bottom with the parent text’s baseline.middle: Aligns the content’s vertical midpoint halfway up the parent’s x-height. (The x-height measures average lowercase letter height.)sub: Moves the baseline slightly below the parent’s, producing subscript. A smaller font can improve the result.super: Moves the baseline slightly above the parent’s, producing superscript. A smaller font can improve the result.text-bottom: Aligns the content’s bottom with the parent element’s bottom, independently of actual line height.text-top: Aligns the content’s top with the parent element’s top, independently of actual line height.
CSS lengths and percentages align inline content as follows:
CSS length: Moves the content’s baseline, or bottom if no baseline exists, relative to the parent baseline: positive values upward, negative downward.
Percentage: Moves the baseline, or bottom if absent, by a percentage of the parent’s line height: positive upward, negative downward.
These keywords align inline content by the parent’s line height. Results can differ substantially from font-size-based alignment:
bottom: Aligns the content’s bottom with the parent line’s bottom.top: Aligns the content’s top with the parent line’s top.
In table cells, sub, super, text-bottom and text-top behave like baseline. The keywords bottom, middle and top refer to the cell box; baseline refers to the table row’s baseline.
Default value: baseline
Compatibility
CSS version: 1 (CSS lengths since CSS2)
Works in Internet Explorer 4+, Opera and Mozilla, including Netscape 6+.
Internet Explorer for Windows through version 5 supports only baseline, sub and super. Version 5.5 accepts all keywords, but only for elements supporting the HTML attribute valign, such as table cells. Internet Explorer for Windows does not support CSS lengths or percentages for vertical-align.
Example
This rule vertically centers all table headings (th) within their table cells:
th {
vertical-align: middle;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg