- From: Ian Hickson <ian@hixie.ch>
- Date: Sat, 25 May 2002 16:43:37 +0100
- To: Liorean <Liorean@user.bip.net>
- CC: www-style@w3.org
Liorean wrote:
>
> I've got a small wondering about the specificity of some selectors,
> namely the attribute selectors [class~="blah"] and [id="blah"], since
> those are, at least in what element they affect equal to the .blah and
> #blah selectors. Are all attribute selectors of the same specificity, or
> does the specificity differ depending on what attribute you look at? If
> it's equal for all attribute selectors, is there any way to raise the
> specificity of [id="blah"] to that of #blah?
CSS2, 5.9:6:
# ID selectors have a higher precedence than attribute selectors. For example,
# in HTML, the selector #p123 is more specific than [ID=p123] in terms of the
# cascade.
> #blah2 #blah { /* Specificity 2,0,0 */
> color: blue;
> }
>
> #blah { /* Specificity 1,0,0 */
> color: red;
> }
>
> [id="blah2"] [id="blah"] { /* Specificity 0,2,0 or 2,0,0? */
> color: green;
> }
0,2,0
>
> [id="blah"] { /* Specificity 0,1,0 or 1,0,0? */
> color: yellow;
> }
>
0,1,0
> [id="blah2"] [id="blah"] { /* Specificity ? (Does this overrule the next
> rule?)*/
> color: maroon !important;
> }
0,2,0, so yes, it overrides the following rule.
>
> [id="blah"] { /* Specificity ? */
> color: olive !important;
> }
0,1,0
> <div id="blah2">
> <div id="blah">
> content
> </div>
> </div>
>
> Will "content" take the colour maroon or olive?
maroon.
--
Ian Hickson
``The inability of a user agent to implement part of this specification due to
the limitations of a particular device (e.g., non interactive user agents will
probably not implement dynamic pseudo-classes because they make no sense
without interactivity) does not imply non-conformance.'' -- Selectors, Sec13
Received on Saturday, 25 May 2002 11:43:42 UTC