When developing a plugin, which is styled by CSS classes, what are some good approaches for making my class names non-conflicting with the existing CSS class names? Has anyone gave it a thought?
3 Answers
Start each class name with a plugin name prefix.
e.g. for a plugin named 'pluginName' and class 'mainBox' use:
$(this).addClass('pluginName-mainBox');
2 Comments
Yotam Omer
Yes, if you believe you will still get into trouble you can use a series of predefined numbers & letters. some programmers use thier domain name etc..
I will use the AJAX combobox CSS as an example:
.ajax__combobox_textboxcontainer
.ajax__combobox_textboxcontainer input
.ajax__combobox_buttoncontainer button
.ajax__combobox_itemlist
after the "." there is the name of the control kit, the double underscore, the name of the control, then the name of the part of that control that is being styled. It is very verbose and definitely helps to avoid conflict. I recommend using an approach like this.