This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Stylesheets > April 2006 > Simple selector question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Simple selector question
Jim Garrison

2006-04-23, 10:43 pm

In reading someone else's stylesheet I ran across the following
two selectors, in the following order.

#footer .label { ... }

[id]#footer .label { ... }


Are these not identical in effect? If not, I'm missing something
about attribute selectors. My reasoning is that in the second selector
[id] is redundant, since anything matching #footer MUST have an id
attribute. (There was no space between the [id] and the #footer).

I looked in the W3C 2.1 spec, and the only thing I could find is that
the second selector has a slightly higher specificity because of the
explicit [id], so it will ALWAYS take precedence over the first rule.

Is this correct?

TIA

Jim Garrison
jhg at acm dot org
Jim Moe

2006-04-23, 10:43 pm

Jim Garrison wrote:
>
> I looked in the W3C 2.1 spec, and the only thing I could find is that
> the second selector has a slightly higher specificity because of the
> explicit [id], so it will ALWAYS take precedence over the first rule.
>
> Is this correct?
>

All other things being equal, yes.
The ruleset with the greatest specificity wins.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
David Dorward

2006-04-24, 4:15 am

Jim Garrison wrote:

> In reading someone else's stylesheet I ran across the following
> two selectors, in the following order.
>
> #footer .label { ... }
>
> [id]#footer .label { ... }


Internet Explorer does not support attribute selectors. This could be being
used as a technique to apply additional styles only to MSIE.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jim Garrison

2006-04-24, 6:54 pm

David Dorward wrote:
> Jim Garrison wrote:
>
>
> Internet Explorer does not support attribute selectors. This could be being
> used as a technique to apply additional styles only to MSIE.
>


Are you saying that the first selector would be used by MSIE, but the
second one would apply in browsers that support attribute selectors?
Alan J. Flavell

2006-04-24, 6:54 pm

On Mon, 24 Apr 2006, Jim Garrison wrote:

> David Dorward wrote:
>
> Are you saying that the first selector would be used by MSIE, but the
> second one would apply in browsers that support attribute selectors?


*Both* of them would apply in supporting browsers, but in the
case of a clash in values, the second one (having higher priority)
would win.
frederick

2006-04-24, 6:54 pm

Alan J. Flavell wrote:
> On Mon, 24 Apr 2006, Jim Garrison wrote:
>
> *Both* of them would apply in supporting browsers, but in the
> case of a clash in values, the second one (having higher priority)
> would win.


It's a less-robust method of achieving the same end as conditional
comments, although with the negligible advantage of only needing one
stylesheet.


--
AGw.

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews