tags:

views:

50

answers:

2

I tried this and it worked in all browsers (IE, FF, Chrome, Opera and Safari):

.classname#id

Still, I can't find this mentioned anywhere on w3c.org, can you point me to where this is mentioned? I mean if this is supported by all those browsers then it must be part of the standard, isn't it?

Many thanks

+4  A: 

You can chain CSS selectors, it's just like using H1.title where you chain a type selector (H1) and a class selector (.title). See http://www.w3.org/TR/css3-selectors/#selector-syntax

zooglash
It's in the css syntax at http://www.w3.org/TR/CSS1/#appendix-b - interestingly it seems to require that the id comes before the class (one the of the alternatives for 'simple_selector' is 'solitary_id class? pseudo_class?', the question marks mean that the class and pseudo_class are optional).
Daniel James
I can't find that syntax or any example that has an id with a class chained together, so it seems they don't mention all possible combinations
Waleed Eissa
Standards usually don't list all possible combinations, at that would result in a much larger document (in many cases an infinitely large one). The syntax allows for this combination and the meaning is defined, and that's enough.
Daniel James
Also, you don't have to always refer to the standards, for most people secondary sources (such as a good text book or reference site) is good enough. And often better as they can discuss relevant information that doesn't belong in the standard.
Daniel James
A: 

It is useless though, only specifying the ID would be enough.

#id

...unless you tried to be clever and used an identifier for more than one element.

GoodEnough
There is a use. You might be using the same CSS on multiple pages - on some pages the element with that id has the class, on others it doesn't.
Daniel James
Right, didn't think of that. Though I would chain in the other order: #id.class
GoodEnough
I'll tell you why I need this. I'm using a suckerfish menu on my site, you know that IE6 supports the hover pseudo-class only on links, suckerfish adds a little javascript to handle this for IE6 (adds a class in onmouseover and removes it in onmouseout), I'm trying the style the first level of LIs, I have two links in the first level with each one having different styles, also every one having different styles when hovered on, so I want something like this: .sfhover#firstmenuitem and .sfhover#secondmenuitem
Waleed Eissa