July 13, 2004
Resolving style conflicts
1)Cascade rules
- (1)Find all declarations for target media
- (2)The primary sort of the declarations is done by origin(the source from which declarations comes: author's, user's, default) and weight(importance of the declarations).
- a)Normal declaration: author---override-->user---override-->default
- b)Important declaration: user---override-->author-override-->default
- c)Important declaration override normal declaration.
- (3)The second sort is by specificity of selector:
- a)more specific selectors override more general ones.
- b)Pseudo-selector and pseudon-classes are counted as normal elements and classes.
- (4)Finally, sorted by order specified.
- a)The latter specified wins.
- b)Imported stylesheets are considered to be placed before any embedded stylesheets.
2)Specificity calculation
- (1)How to yield the specificity of each selector?
- a)Count the number of ID selectors in the selector(=a)
- b)Count the number of other selectors and pseudo-class selectors in the selector(=b)
- c)Count the number of element names in the selector(=3)
- d)Ignore pseudo-elements
- e)Concatenation the 3 values: a-b-c to yield the specificity
- (2)Which one is bigger?
- a)The one has a bigger "a"
- b)Otherwise ,the one has a bigger "b"
- c)Otherwise, the one has a bigger "c"
- d)Important declaration always outweigh non-important declarations.
3)Importance
- (1)Declarations may be marked as important using the "!important" construct.
- (2)"!important" is applied to actual declarations , not to selector nor to rules.
4)Inheritance
- (1)Many styles can be inherited from a element to its descendant elements.
- (2)All properties except "page" can be given a value "inherit" .
5)Shorthand Properties
- (1)A few CSS properties which one properties represent a much large collection of properties.
- (2)"text-decoration" is a shorthand for no properties at all but acts much as a shorthand properties does.
参考资料:
Eric Meyer, CSS 2.0 Programmer's Reference.
Posted by Hilton at July 13, 2004 06:32 PM
| TrackBack
You are invited to check the sites about...