Or Weinberger
Or Weinberger

Reputation: 7482

How to make sure your CSS rules are not overridden

I've developed a simple jQuery plugin that has some styled divs,

However when users implement my code in their websites the divs often look bad due to some CSS rules on the original website that are overriding mine.

My class names are unique but that doesn't help in case the user has a css rule set for div for example

Upvotes: 1

Views: 2137

Answers (3)

Gennady Dogaev
Gennady Dogaev

Reputation: 5991

As far as I know, div.className have higher priority than div. You can try use this. Also you need to define all major attributes (such as margins, borders, etc). Using "!important" - not good style in case of plugin development because some ppl will need to redefine your css-classes according to their page design.

Upvotes: 1

alexjewell
alexjewell

Reputation: 31

Unless you type every single CSS rule you can think of to enforce, using !important where necessary to ensure priority, you really can't overwrite styles you can't specifically refer to. Perhaps you can choose the 10 most problematic rules - color, border, padding, margin, etc. - and simply include those.

Upvotes: 1

bittenbytailfly
bittenbytailfly

Reputation: 233

You can use the !important flag in css to ensure rules aren't overridden, but they're still prone to errors if everyone else uses them of course:

p {
    color: red !important;
}

Upvotes: 2

Related Questions