2008 Nov 04
Styles can be applied in different ways and there are cascade rules which specify which ways override others.
The most overriden way is:
<html> <head> <title>...</title> <link rel="stylesheet" <!-- required --> type="text/css" <!-- required --> href="rules.css" <!-- url of external style sheet --> media="all" <!-- optional --> title="Funny" <!-- rarely used --> /> </head> <body> ... </body> </html> |
Multiple style sheets can be loaded by using more than one link elements, in which case the combining rules apply.
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="foo.css"?> <name_space:root_element_name ... > ... </name_space:root_element_name ...> |
The next most overriden way is:
<html> <head> <title>...</title> <style type="text/css"> ... style statements ... </style> </head> <body> ... </body> </html> |
Optionally, (and as the) first element within the style element (before any rules), there can be one or more imports:
@import url(rules.css);
i.e. before the style statements. As with link the import directive can be qualified with a media attribute list, e.g.:
@import url(rules.css) screen, print;
The least overriden way is to have a style in an element with specific attributes, or with the style attribute, e.g.:
<p style="color: teal;">text...text</p>
The new style attribute is like a CSS rule except that the curly braces are replaced with double quotes. The style attribute is not recommened.
Which results in precedence by weight:
Value | Meaning |
---|---|
stylesheet | Use in all presentation media. |
alternate stylesheet | Allows the user to choose style when properly implemented. |
Value | Meaning |
---|---|
all | Use in all presentation media. |
aural | Use in speech syhthesizers, screen readers, etc. |
braille | Use with Braille rendering devices. |
embossed | Use when printing with a Braille printer. |
handheld | Use on handheld devices (e.g. pda's or cell phones). |
Use when printing the document or during print preview. | |
projection | Use with projection devices. |
screen | Use with monitor. |
tty | Use with fixed-pitch devices like a teletype. |
tv | Use when document is presented on a television. |
The media attribute value can be a comma separated list, e.g.:
media="print,aural"
Note that not all media values are supported by most browsers.
If a title attribute is not given then the referenced style is persistent, i.e. is always used.