When combining a class and ID in CSS is it better practice to use .class#id or #id.class? Does one have advantages over the other, or are they treated exactly the same by every browser? Thoughts?
Asked
Active
Viewed 5,722 times
2 Answers
3
They both point to the same element due to that id
selector, so they work the same way.
As for advantages, I feel that .class#id
is suited more for specific cases of a .class
element (like a sticky post in a blog), and a #id.class
is just an extension of the #id
element's stylesheet.
I'm not sure if this is common practice, but I find it helpful.

Blender
- 289,723
- 53
- 439
- 496
2
I believe you can find some useful information here:
How to combine class and ID in CSS selector?
-
So it looks like #id.class is the accepted usage. Strangely, both variations work in modern browsers. – bjork24 Jan 20 '11 at 16:15
-
I would say luckily both variantions work in modern browsers :) – Mr. L Jan 20 '11 at 16:39