Wednesday, October 8, 2008

Font Size - Relative Size Keywords with Absolute Keyword Sized Text

The relative size keywords can be applied to text whose inherited size was specified using the absolute size keywords. Each browser handles this combination differently.

Firefox 3 and Internet Explorer 6 and 7

When the larger keyword is used with absolute keyword sized text, Firefox 3 and Internet Explorer 6 and 7 will "upgrade" the text size to the next higher absolute keyword's size.
Example: <p style="font-size:medium">Some text here <span style="font-size:larger">larger span text</span>
In this example, the inherited font size is medium which translates to 16px. Therefore, Firefox 3 or Internet Explorer 6 and 7 will increase the span text's font size to 18px which is equivalent to the absolute size keyword large.
When the keyword larger is applied to text sized with xx-large, Firefox 3 and Internet Explorer 6 and 7 multiply the font size by 1.5.
Example: <p style="font-size:xx-large">Some text here <span style="font-size:larger">larger span text</span>
The keyword xx-large corresponds to a font size of 32px. If to this the keyword larger is applied the resulting font size is 32 * 1.5 = 48px .
When the smaller keyword is used with absolute keyword sized text, Firefox 3 and Internet Explorer 6 and 7 will "downgrade" the text size to the next lower absolute keyword's size.
When the keyword smaller is applied to text sized with xx-small Firefox 3 divides the font size by approximately 1.13 .
Example: <p style="font-size:xx-small">Some text here <span style="font-size:smaller">larger span text</span>
The keyword xx-small corresponds to a font size of 9px. If to this the keyword smaller is applied, the resulting font size is 9 / 1.13 = 8px (approx.). However, Internet Explorer 6 and 7 don't behave this way. Therefore, using the relative size keyword smaller with text whose inherited font size is xx-small is not recommended.

Opera 9.5

When the larger keyword is used with absolute keyword sized text, Opera 9.5 does not "upgrade" the text size to the next higher absolute keyword's size. Instead, it multiplies the font size by approximately 1.2 .
When the smaller keyword is used with absolute keyword sized text, Opera 9.5 does not "downgrade" the text size to the next lower absolute keyword's size. Instead, it divides the font size by a number ranging from 1.1 to 1.29 .

Safari 3.1

When the larger keyword is used with absolute keyword sized text, Safari 3.1 does not "upgrade" the text size to the next higher absolute keyword's size. Instead, it multiplies the font size by approximately 1.2 .
When the smaller keyword is used with absolute keyword sized text, Opera 9.5 does not "downgrade" the text size to the next lower absolute keyword's size. Instead, it divides the font size by approximately 1.2 . However, if the resulting font size is less than 9px , it is ignored and the font size is made 9px . Therefore, the font size is never less than 9px .

Advantages and Disadvantages

There is no consistency across browsers in the application of the relative keywords to text that has been sized with absolute keywords. Therefore, this combination of keywords must be avoided.
Here is a table showing the resulting font sizes when the relative keywords are applied to text that was sized with absolute keywords. All the sizes are in px, smaller smaller and larger larger indicate nested relative keywords ie. the relative keyword was applied twice through nested elements.
Relative sizing of text that was sized with absolute size keywords
keywordsizesmallersmaller-smallerlargerlarger-larger
xx-small9871013Firefox 3
x-small10981316
small131091618
medium1613101824
large1816132432
x-large2418163248
xx-large3224184872
xx-small9871113Opera 9.5
x-small10981214
small131091619
medium1613101923
large1814122226
x-large2419152935
xx-large3226203846
xx-small9641013IE6 , IE7
x-small10741316
small131071618
medium1613101824
large1816132432
x-large2418163248
xx-large3224184872
xx-small9991113Safari 3.1
x-small10991214
small131191619
medium1613111923
large1815122226
x-large2420172935
xx-large3227223846

No comments: