1

I'm looking to develop a plugin that can be added to many different websites, but I need to limit the possibility of the existing CSS on the site effecting my plugin.

Obviously I can have a container around my plugin which is the prefix to all my CSS rules, but how can I prevent an existing rule such as this cocking things up?: a { display: none; }. Is there some sort of generic CSS reset I can do on all tags that would normalize, in this case, A tags to display inline?

7
  • You could set your styles to !important, that way they wouldn't get overwritten. Example a { display: inline !important;} Commented Feb 18, 2015 at 21:25
  • If you use a reset, be sure to target only the elements affected by your plugin to avoid unintended changes to other elements. Also, consider using the !important operator. Its use is often seen as an antipattern, but in this case, it might be just what the doctor ordered. Commented Feb 18, 2015 at 21:26
  • !important is going to be mostly unnecessary. I would advise against using it even in this case unless there are inline styles. Considering you are already planing on prefixing your rules with some class or ID, it should naturally increase the specificity. Just make sure your plugin style sheets are loaded after the main one and maintain that specificity and it should be fine in most cases. Otherwise, look into CSS reset style sheets and administer where needed (such as the rules for anchors for example). Commented Feb 18, 2015 at 21:29
  • Don't style global elements like <a> <p> <body> etc. Always prefix with something unique. Otherwise your plugin styles will override other styles on the users' websites and this most often produces undesirable results. When that occurs, the first thing to happen is that your plugin gets uninstalled. Then you're left negative feedback. You'll want to do it right and prefixing your styles are how it's done. Commented Feb 18, 2015 at 21:33
  • possible duplicate of How to break CSS inheritance? Commented Feb 18, 2015 at 21:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.