Sunday, March 7, 2010

Length Units (em)

A length value is formed by an optional + or -, followed by a number, followed by a two-letter abbreviation that indicates the unit. There are no spaces in a length value; e.g., 1.3 em is not a valid length value, but 1.3em is valid. A length of 0 does not require the two-letter unit identifier.

The following relative units are available:

em (ems, the height of the element's font)
ex (x-height, the height of the letter "x")
px (pixels, relative to the canvas resolution)

The 'em' unit is equal to the computed value of the 'font-size' property of the element on which it is used. The exception is when 'em' occurs in the value of the 'font-size' property itself, in which case it refers to the font size of the parent element. It may be used for vertical or horizontal measurement.


e.g
h1 { line-height: 1.2em }
means that the line height of "h1" elements will be 20% greater than the font size of the "h1" elements. On the other hand:
h1 { font-size: 1.2em }
means that the font-size of "h1" elements will be 20% greater than the font size inherited by "h1" elements.

No comments:

Post a Comment