Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector style?

Tags:

css

Sometimes I find myself creating a CSS class for a single element. So instead, I can use an ID and set a rule for this ID. Which way is preferable stylistically?

like image 987
akonsu Avatar asked May 24 '26 21:05

akonsu


1 Answers

I'd say that this is more of a person-by-person preference.

For me, I try to think ahead: will I ever create two of these on one page? If the answer is even vaguely "yes," then I use classes. If I can't see the need for creating a second of the particular element, I'll use an ID.

In terms of the ID itself, I try to name it something that I won't conflict with. For instance, I'll choose something like:

#aboutus_team_wrapper {}

It's long and ugly, but I know exactly what it's for, where I'm using it, and I know I'll never create something that conflicts with the name.

Hope this helps!

like image 73
mattbasta Avatar answered May 26 '26 15:05

mattbasta