Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining class and ID in your CSS selector, best practice?

Tags:

css

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?

like image 529
bjork24 Avatar asked Jan 27 '26 03:01

bjork24


2 Answers

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.

like image 59
Blender Avatar answered Jan 29 '26 20:01

Blender


I believe you can find some useful information here:
How to combine class and ID in CSS selector?

like image 28
Mr. L Avatar answered Jan 29 '26 18:01

Mr. L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!