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 [1] below. Considering the specificity of selectors, possible inheritance, and the effects of inline styles, the final set of declarations which apply to [1] 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 1 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 parent) |
3 | div | This selects selects any div element. | no | yes (from parent) |
4 | li:first-child | This selects any li element that is a first child. | no | no |
5 | li | This selects any li element. | no | no |
6 | div[id] p | This selects any p element that is a descendant of a div element with an id attribute. | yes | no |
7 | div#content | This selects any div element with an #ID that equals content. | no | yes (from parent) |
8 | *#content p | This selects any p element that is a descendant of any element with an #ID that equals content. | yes | no |
9 | inline style | This selects an inline p | yes | no |
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 parent) |
3 | div | This selects selects any div element. | no | yes (from parent) |
6 | div[id] p | This selects any p element that is a descendant of a div element with an id attribute. | yes | no |
7 | div#content | This selects any div element with an #ID that equals content. | no | yes (from parent) |
8 | *#content p | This selects any p element that is a descendant of any element with an #ID that equals content. | yes | no |
9 | inline style | This selects an inline p | yes | no |
Rule# | Selector | author | user |
---|---|---|---|
2 | h1[id|="pg"] + * + div | yes | no |
3 | div | yes | no |
6 | div[id] p | yes | no |
7 | div#content | yes | no |
8 | *#content p | no | no |
9 | 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 |
6 | div[id] p {font-weight: normal;} | no | no |
7 | div#content | no | no |
8 | *#content p | 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 |
6 | div[id] p {font-weight: normal;} | no | no |
7 | div#content | no | no |
8 | *#content p | no | no |
9 | inline style | no | no |
Rule# | Selector | imported |
---|---|---|
2 | h1[id|="pg"] + * + div | no |
3 | div {font-weight: bold;} | no |
6 | div[id] p {font-weight: normal;} | no |
7 | div#content | no |
8 | *#content p | 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 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
This selects any div element.
A div element that matches this selector 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
This selects any p element that is a descendant of a div element with an id attribute.
This selects any div element with an #ID that equals content.
A div element that matches this selector 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
This selects any p element that is a descendant of any element with an #ID that equals content.
In HTML, values of an element's "style" attribute are style sheet rules. These rules have no selectors, but for the purpose of step 3 of the cascade algorithm, they are considered to have an ID selector (specificity: a=1, b=0, c=0).6.4.3 Calculating a selector's specificity
Specificity | Rule# | Selector | color: | background: | font-weight: | font-style: | border: | padding: |
---|---|---|---|---|---|---|---|---|
none (inherited) |
2 |
h1[id|="pg"] + * + div |
#333 | normal | ||||
none (inherited) |
3 | div | bold | |||||
none (inherited) |
7 | div#content | black | yellow | 1px solid brown non-standard color name |
0.5em | ||
0-1-2 | 6 | div[id] p | normal | |||||
1-0-0 | 9 inline style |
inline style | bold | italic | ||||
1-0-1 | 8 | *#content p | normal |
If two rules have the same:
the latter specified wins.
Specificity | Rule# | Selector | color: | background: | font-weight: | font-style: | border: | padding: |
---|---|---|---|---|---|---|---|---|
none (inherited from parent) |
2 | h1[id|="pg"] + * + div | #333 | normal | ||||
none (inherited from parent) |
3 | div | bold | |||||
none (inherited from parent) |
7 | div#content | black | yellow | 1px solid brown non-standard color name |
0.5em | ||
0-1-2 | 6 | div[id] p | normal | |||||
1-0-1 | 8 | *#content p | normal | |||||
1-0-0 | 9 inline style after all other rules |
inline style | bold | italic | ||||
The winner | black | yellow [note] |
bold | italic | 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; color:
black;}
<p style="font-weight: bold; font-style:
italic;">