I’m developing my first really major wordpress plugin and I’m not sure how to approach specificity.
I want to avoid inline styling completely yet I want to ensure my css declarations aren’t interfered with by other plugins or themes. While I can and will test it with several different themes before release, I want to ensure that I do everything possible at the dev stage.
So with that in mind, should I maintain a minimum specificity for all my CSS declarations? From my experience, I’m reckoning that if a theme declaration has a specificity higher than (0,1,0,0) then it’s likely to be specific to an ID anyway so very unlikely to interfere with my declarations. So as a rule of thumb I’ve been maintaining a minimum specificity of (0,1,1,0) in my declarations, but I don’t know if this is good enough. I’m 99% sure that all my ID’s are absolutely unique to my plugin.
Is there any documentation or standards for this that I should work to ensure that my CSS is good?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
There’s no standard. CSS specificity in themes varies wildly, and I’m convinced many theme authors are not even aware of the concept given some of the CSS I’ve seen.
If something is very important to the appearance of your plugin, then high specificity may be desirable, but in many cases if you’re just styling divs with unique class names, or form elements, then you should keep specificity low so than it can inherit styles from the theme as appropriate.
So really it’s case by case, and you’re not going to be able to guarantee results with all themes. A good rule of thumb is that your specificity should reflect how important it is that the styles are respected.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0