Page is a not externally linkable
- Code, Content, and Presentation
-- CSS
---- Use efficient CSS selectors


SuzyUK - 2:34 pm on Dec 8, 2009 (gmt 0)


nothing is wrong.. Google is just being over zealous as usual :)

basically they are saying they would like us to add class names to every single element and use them in our CSS instead of the descendant (or any other type of existing) selectors.

As for qualifying the selector, that's where you are using ul.classname they are saying not to use the ul (just .classname)

It may well be you don't have to use the element to qualify the selector if you are only using that classname in one place (like an ID). but if the classname AND CODE is to be reusable such selectors would need to be qualified, - So which is to be reusable code or more classes? ;)

Honestly I'm fed up with SE's dictating how we should write/use CSS it's nothing to do with them.

Interestingly Steve Sounders (ex Yahoo now Google) ran some tests on "inefficient" selectors and found that you would need thousands of elements and CSS before the type of selectors is likely to affect the speed of any site in a noticeable fashion.
Source [stevesouders.com]
.. For 70% or more of today’s users, improving these CSS selectors would only make a 20 ms improvement.

Keep in mind - these test pages are close to worst case.

and later in the replies he does advise (answering someone asking about a tag cloud with hundreds of links)
paraphrased

Q. Would you prefer using the rule
#tag-cloud > a OR .tag-cloud-link

A: If the styling is not inherited and the page doesn’t has only a few hundred A tags, I would do #tag-cloud > A. If the page has thousands of A tags, I would do the class.

so again backing up the theory that it would take literally thousands of elements to make this worthwhile?

FWIW I ignore those warnings, I like my descendant selectors and child selectors both for keeping style sheets neat and also maintaining specificity - also I consider this not yet proved enough to spend any extra coding time needed just for a very minor imperceptible gain!

Maybe bear in mind Google and Yahoo both want everyone to write stylesheets with classes alone, this would increase CSS file sizes and introduce classisits and divitis, is not likely to speed up or slow down sites either way BUT I think it would make stylesheets a lot easier for them to parse as they can't read specificity/inheritance very well, ... if I was really paranoid I might just ay they even might be capable of "bending" the truth if it suited their purposes slightly better ;)


Thread source:: http://www.webmasterworld.com/css/4039425.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com