When naming classes and IDs for CSS what is the best method to use. In this case I need there to be some kind of naming convention so that other people can pick up rules and understand how to name their own ids and classes using the same pattern. Any suggestions? Some of the sites we create can get pretty complex but use an overall structure header, content and footer. The naming must be efficient too.
I am not new to CSS. I am aware of giving them names that represent their structure etc., but just want to know people opinions really and ways of doing this.
There is no real naming convention. Just agree on one with your team and keep it consistent. For instance don't mix camel case and snake case.
Try to be as description as possible when naming a class. Example:
edit; Worse naming convention I saw is using the actual content of the styling. For instance:
... because when I got to the code (legacy code), but "red button" was not red but blue (or something like that).
Try to use something that will not likely change, like the purpose of the class.
The best advice is to use class with semantics in mind
from this article