This site is designed for accessibility. Content is obtainable and functional to any browser or Internet device. This site's full visual experience is available in a graphical browser that supports web standards. Please consider upgrading your web browser.
Given the following document markup, the following process determines the final set of declarations which apply the numbered element [2] below. Considering the specificity of selectors, possible inheritance, and the effects of inline styles, the final set of declarations which apply to [2] is at the very end of this document.
Declarations apply if the associated selector matches the element in question for the target media type. Reference: Example 2 document tree.
Rule# | Selector | Meaning | Does it match? | Is it inherited? |
---|---|---|---|---|
1 |
*[id~="pg-title"] |
This selects any element with an id attribute that contains the word pg-title. | no | no |
2 |
h1[id|="pg"] + * + div
|
This selects any div element that immediately follows any element that immediately follows a h1 element with an id attribute that equals pg or begins with pg-. | no | yes (from grandparent) |
3 | div | This selects selects any div element. | no | yes (from grandparent) |
4 | li:first-child | This selects any li element that is a first child. | no | no |
5 | li | This selects any li element. | yes | no |
6 | div[id] p | This selects any p element that is a descendant of a div element with an id attribute. | no | no |
7 | div#content | This selects any div element with an #ID that equals content. | no | yes (from grandparent) |
8 | *#content p | This selects any p element that is a descendant of any element with an #ID that equals content. | no | no |
9 inline |
inline ol | This selects an inline ol. | no | yes (from parent) |
Disregard the ones that don't match. These styles remain:
Rule# | Selector | Meaning | Does it match? | Is it inherited? |
---|---|---|---|---|
2 |
h1[id|="pg"] + * + div
|
This selects any div element that immediately follows any element that immediately follows a h1 element with an id attribute that equals pg or begins with pg-. | no | yes (from grandparent) |
3 | div | This selects selects any div element. | no | yes (from grandparent) |
5 | li | This selects any li element. | Yes | no |
7 | div#content | This selects any div element with an #ID that equals content. | No | yes (from grandparent) |
9 inline |
inline ol | This selects an inline ol. | no | yes (from parent) |
Rule# | Selector | author | user |
---|---|---|---|
2 | h1[id|="pg"] + * + div | yes | no |
3 | div | yes | no |
5 | li | yes | no |
7 | div#content | yes | no |
9 inline style |
inline style | yes | no |
!importantdeclarations, user style sheets override author style sheets which override the default style sheet.
Rule# | Selector | !important author |
!importantuser |
---|---|---|---|
2 | h1[id|="pg"] + * + div | no | no |
3 | div {font-weight: bold;} | no | no |
5 | li {color: maroon;} | no | no |
7 | div#content | no | no |
9 | inline style | no | no |
!importantdeclaration override normal declarations.
Rule# | Selector | !important |
normal |
---|---|---|---|
2 | h1[id|="pg"] + * + div | no | no |
3 | div {font-weight: bold;} | no | no |
5 | li {color: maroon;} | no | no |
7 | div#content | no | no |
9 | inline style | no | no |
Rule# | Selector | imported |
---|---|---|
2 | h1[id|="pg"] + * + div | no |
3 | div {font-weight: bold;} | no |
5 | li {color: maroon;} | no |
7 | div#content | no |
9 | inline style | no |
All the same weight and origin (author). No "!important" declarations, no imports.)
Examine and rate each selector.
This selects any div element that immediately follows (is sibling to) any element that immediately follows (is sibling to) a h1 element with an id attribute that equals pg or begins with pg-.
A div element that matches this selector is the grandparent of the target so the specificity of inherited values comes into play.
Specificity = none
Inherited values don't have a specificity of 0. They don't have any specificity at all.-Eric Meyer 21.1.1
This selects any div element.
A div element that matches this selector is the grandparent of the target so the specificity of inherited values comes into play.
Specificity = none
Inherited values don't have a specificity of 0. They don't have any specificity at all.-Eric Meyer 21.1.1
This selects any li element.
This selects any div element with an #ID that equals content.
A div element that matches this selector is a grandparent of the target so the specificity of inherited values comes into play.
Specificity = none
Inherited values don't have a specificity of 0. They don't have any specificity at all.-Eric Meyer 21.1.1
An ol element is the parent of the target so the specificity of inherited values comes into play.
Specificity = none
Inherited values don't have a specificity of 0. They don't have any specificity at all.-Eric Meyer 21.1.1
Specificity | Rule# | Selector | color: | background: | font-weight: | font-style: | border: | padding: |
---|---|---|---|---|---|---|---|---|
none (inherited) |
3 | div | bold | |||||
none (inherited) |
2 | h1[id|="pg"] + * + div | #333 | normal | ||||
none (inherited) |
7 | div#content | black | yellow | 1px solid brown non-standard color name |
0.5em | ||
none (inherited) |
9 inline style |
inline ol inherited |
gray | |||||
0-0-1 | 5 | li explicit |
maroon |
If two rules have the same:
the latter specified wins.
Specificity | Rule# | Selector | color: | background: | font-weight: | font-style: | border: | padding: |
---|---|---|---|---|---|---|---|---|
none (inherited from grandparent) |
2 | h1[id|="pg"] + * + div | #333 | normal | ||||
none (inherited from grandparent) |
3 | div | bold | |||||
none (inherited from grandparent) |
7 | div#content | black | yellow | 1px solid brown non-standard color name |
0.5em | ||
none (inherited from parent, closest ancestor) |
9 inline style |
inline ol |
gray | |||||
0-0-1 | 5 |
li |
maroon | |||||
The winner | maroon | yellow [note] |
bold | border
doesn't inherit |
padding
doesn't inherit |
[note] Background properties are
not inherited, but the parent box's background will shine
through by default because of the initial 'transparent' value
on 'background-color'.
14.2
div#content {background: yellow;}
div {font-weight: bold;}
li {color: maroon;}