Friday, October 10, 2008

Font Size - Relative Size Keywords With Relative Length Units (px, em, ex) and Percentage Values

The relative size keywords can be applied to text whose inherited size was specified using percentage values or the relative length units px, em and ex. Unfortunately, with a given combination of relative size keywords and relative length units (or percentage values), the resulting font size varies across browsers.
In a particular browser, whether the font size is inherited from relative length units or percentage values, for a particular computed font size, the relative size keywords behave the same (except for IE6 and IE7 when the computed size is 18px).
Example 1:<p style="font-size:0.9em">Text at the inherited size and <span style="font-size:larger">larger text</span> and <span style="font-size:smaller">smaller text</span></p>

Example 2:<p style="font-size:9px">Text at the inherited size and <span style="font-size:larger">larger text</span> and <span style="font-size:smaller">smaller text</span></p>

Example 3:<p style="font-size:90%">Text at the inherited size and <span style="font-size:larger">larger text</span> and <span style="font-size:smaller">smaller text </span></p>

Example 4:<p style="font-size:1.8ex">Text at the inherited size and <span style="font-size:larger">larger text</span> and <span style="font-size:smaller">smaller text</span></p>
Advantages and Disadvantages: The application of relative size keywords to text whose inherited size was specified using percentage values and the relative length units px, em and ex results in inconsistent font sizes across browsers. Therefore, this combination must be avoided if consistent appearance across browsers is desired.

Notes and Example Data:
Firefox 3: If the keywords larger or smaller are applied to text whose computed size corresponds to an absolute keyword font size (9, 10, 13, 16, 18, 24 and 32 pixels), then FF3 "upgrades" or "downgrades" the text to the nearest absolute keyword's font size.
For other computed sizes, FF3 multiplies or divides the computed font size by a number ranging from 1.11 to 1.5 .
Opera 9.5: Opera's relative keyword scaling of 9, 10, 13, 16, 18, 24 and 32 pixels sized text is also consistent with its absolute keyword scaling. For other px sizes, Opera 9.5 multiplies or divides with a number ranging from 1.11 or 1.29 .
IE7 and IE6: The relative keyword scaling of 9, 10, 13, 16, 18, 24 and 32 pixels sized text is not consistent with its absolute keyword scaling. The scaling of 10px and 13 px with the keyword smaller does not match the scaling of x-small and small with smaller.
IE6 and IE7 multiplies or divides the relative keywords with a number ranging from 1 to 1.5
Safari 3.1: Safari's relative keyword scaling of 9, 10, 13, 16, 18, 24 and 32 pixels sized text is largely consistent with its absolute keyword scaling with the exception that font sizes are allowed to go below 9px.
Safari 3.1 does relative keyword scaling by multiplying or dividing by a figure ranging from 1.12 to 1.29
Internet Explorer 6 and 7 relative size keyword bug:
largerlarger-larger
parent style: font-size: 18px18 24
ancestor font size = 10px inherited font size: 1.8em or 3.6ex or 180%2432

The first row shows the resulting font size in pixels when the inherited font size was specified as 18px. The second row shows the resulting font size when the ancestor font size was 10px and the inherited font size was specified as 1.8em or 3.6em or 180% (which results in a computed value of 18px).
The resulting font size is supposed to the same - that is, both the rows should have the same pair of values. This is an IE6 and IE7 bug.
Here is a table that shows the resulting font size when the relative keywords are applied to text with various inherited font sizes. All font sizes are in pixels. The columns smaller-smaller and larger-larger indicate nested relative keywords ie. the relative keyword was applied twice through nested elements.
Table Caption: Relative sizing of text with inherited font size from relative length units or percentage values
inherited font sizesmallersmaller-smallerlargerlarger-larger
9871013Firefox 3
10981316
11981417
121091517
131091618
141191720
1512101722
1613101824
1715122128
1816132432
1916142535
2418163248
3224184872
9871113Opera 9.5
10981214
11981316
121091517
131091619
141191720
1512101822
1613101923
1714112024
1814122226
1915122327
2419152935
3226203846
9641013IE6 , IE7
10741013
111071316
121071316
131071316
1413101618
1513101618
1613101824
1716131824
1816132432
1918162432
2418163248
3224184872
9761113Safari 3.1
10871214
11981316
121081417
131191619
1412101720
1512101822
1613111923
1714122024
1815122226
1917132327
2420172935
3227223846

No comments: