Web Design Web Design Forum
Registration is free! Here you can view your subscribed threads, work with private messages and edit your profile and preferences Calendar Find other members Frequently Asked Questions Search
Home Web Design

Convenient web based access to our favorite web design Usenet groups

web design reviews

This is Interesting: Free Magazines for Graphics designers and webmasters  





  Last Thread  Next Thread
Author
Thread Post New Thread   

Calculating CSS Selector Specificity
 

sajid@fendoo.com




quote this post edit post

IP Loged report this post

Old Post  08-25-06 - 11:35 AM  
The CSS 2.1 Specification describes how to sort a list of selectors in
order of specificity, but it doesn't provide a method to calculate the
specificity of a single selector in isolation.

I've devised a method to do this, which I describe in the following
article:

http://calculating-css-selector-spe...y.blogspot.com/

Comments and/or criticisms welcome.



Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

Harlan Messinger




quote this post edit post

IP Loged report this post

Old Post  08-25-06 - 11:45 PM  
sajid@fendoo.com wrote:
> The CSS 2.1 Specification describes how to sort a list of selectors in
> order of specificity, but it doesn't provide a method to calculate the
> specificity of a single selector in isolation.

Of course they do. www.w3.org/TR/CSS2/cascade.html#specificity

>
> I've devised a method to do this, which I describe in the following
> article:
>
> http://calculating-css-selector-spe...y.blogspot.com/

In which you wrote, "A method currently popular is to simply concatenate
the numbers a, b, c and d into a single decimal number

Selector	Specificity	Specificity Value
p#title.red	0, 1, 1, 1	0111 = 111

But this method fails if one of b, c, or d is greater than 9."

This demonstrates that you overlooked their examples, in which they did
exactly this--concatenating the numbers, treating them as digits base
10--and the part where they wrote "in a number system with a large
base", which deals head-on with the case where any of the numbers is
greater than 9. In other words, this isn't a "method currently popular".
It's the way the computation was defined.


Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

VidTheKid




quote this post edit post

IP Loged report this post

Old Post  08-26-06 - 11:33 PM  
sajid@fendoo.com wrote:
> The CSS 2.1 Specification describes how to sort a list of selectors in
> order of specificity, but it doesn't provide a method to calculate the
> specificity of a single selector in isolation.

Yes it does, although it doesn't exactly result in a "number" in the
strictest mathematical or physical sense, considering its base might as
well be infinity. And why is such a calculation important?  Why would
anyone need to know how specific a selector is unless they need to know
whether it "wins" over another selector?  That's kind of like trying to
measure the "absolute voltage" of something -- voltage is always
measured as a difference in potential between two points.

--
Vid the Kid



Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

Stephen Poley




quote this post edit post

IP Loged report this post

Old Post  08-26-06 - 11:33 PM  
On 25 Aug 2006 00:58:41 -0700, sajid@fendoo.com wrote:

>The CSS 2.1 Specification describes how to sort a list of selectors in
>order of specificity, but it doesn't provide a method to calculate the
>specificity of a single selector in isolation.
>
>I've devised a method to do this, which I describe in the following
>article:
>
>http://calculating-css-selector-spe...y.blogspot.com/
>
>Comments and/or criticisms welcome.

What do you plan to do with these numbers when you have calculated them?
The "specificity of a single selector in isolation" appears to be a
meaningless concept. A single selector in isolation will always be
applied.

--
Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/


Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

sajid@fendoo.com




quote this post edit post

IP Loged report this post

Old Post  08-28-06 - 11:38 PM  
> But this method fails if one of b, c, or d is greater than 9."
>
> This demonstrates that you overlooked their examples, in which they did
> exactly this--concatenating the numbers, treating them as digits base
> 10--and the part where they wrote "in a number system with a large
> base", which deals head-on with the case where any of the numbers is
> greater than 9. In other words, this isn't a "method currently popular".
> It's the way the computation was defined.

Harlan, you are refering to the CSS 2 specification.

The CSS 2.1 Specification switched to defining the specificity of a
selector as comma-delimited quad of integers for the precise reason I
give.

Follow the linke below for more information:

http://meyerweb.com/eric/css/link-specificity.html



Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

sajid@fendoo.com




quote this post edit post

IP Loged report this post

Old Post  08-28-06 - 11:38 PM  

> Yes it does, although it doesn't exactly result in a "number" in the
> strictest mathematical or physical sense, considering its base might as
> well be infinity.

You're right, it does.

But my point is precisely the fact that the definition doesn't result
in a number.

> And why is such a calculation important?  Why would
> anyone need to know how specific a selector is unless they need to know
> whether it "wins" over another selector?

I don't know if it's important or not.

All I'm saying is: here's a way to do it if you think you'll find it
useful.

>That's kind of like trying to
> measure the "absolute voltage" of something -- voltage is always
> measured as a difference in potential between two points.

Voltage and other physical units may be relative but specificity isn't.


My article demonstrates this precise fact !

viz. Specificity is more like the abstract concept of number, you can
refer to the  absolute specificity of a selector in the same sense that
you can refer to the absolute size of a number.



Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

Harlan Messinger




quote this post edit post

IP Loged report this post

Old Post  08-28-06 - 11:38 PM  
sajid@fendoo.com wrote: 
>
> Harlan, you are refering to the CSS 2 specification.
>
> The CSS 2.1 Specification switched to defining the specificity of a
> selector as comma-delimited quad of integers for the precise reason I
> give.

Hmm, don't know why my link wasn't updated. It doesn't matter, though.
What you wrote is what 2.0 had, and I figure they dropped it from 2.1
because while it was meant to help explain it, it probably just caused
more confusion, and for no purpose, because as has been pointed out to
you, an absolute number doesn't mean anything.

How do you compare numbers you see on paper? How do you alphabetize
words? By exactly the same process used in the spec for the
comma-separated numbers. The only difference between the comma-separated
convention and the rendering of a number to some base is the presence or
absence of the commas! Conceptualizing the specificity as an absolute
number rather than as a set of values adds nothing.


Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

sajid@fendoo.com




quote this post edit post

IP Loged report this post

Old Post  08-28-06 - 11:39 PM  
> What do you plan to do with these numbers when you have calculated them?

I don't know.

It's just something I'm placing in the public domain which other people
might find useful.

> The "specificity of a single selector in isolation" appears to be a
> meaningless concept. A single selector in isolation will always be
> applied.

It's not a meaningless concept because semantically it is identical to
the comma-delimited quad notation.

Whether it's a useful concept or not, I don't know.

The posters so far in this thread (unanimously) do not seem to think
it's useful concept but maybe other people might.



Post Follow-Up to this message ]
Re: Calculating CSS Selector Specificity
 

Harlan Messinger




quote this post edit post

IP Loged report this post

Old Post  08-28-06 - 11:39 PM  
sajid@fendoo.com wrote: 
>
> I don't know.
>
> It's just something I'm placing in the public domain which other people
> might find useful.

W3 placed it in the public domain years ago.


Post Follow-Up to this message ]
Sponsored Links
 





All times are GMT. The time now is 05:39 PM. Post New Thread   
  Previous Last Thread   Next Thread next
Stylesheets archive | Show Printable Version | Email this Page | Subscribe to this Thread

Popular forums

Adobe Photoshop forum Macromedia Flash Web Site Design
Dreamweaver FrontPage forum
JavaScript Forum XML forum
Style Sheets VRML
Forum Jump:
Rate This Thread:

 

XML RSS Feed web design latest articles Syndicate our forum via XML or simple JavaScript

Web Design archive  Database administration help  


Top Home  -  Register  -  Control Panel   -  Memberlist  -  Calendar  -  Faq  -  Search Top