Why is my CSS being overridden by other CSS when I used !important? I even used it inline:


<style type="text/css">
tag {mystyle: inherit 10px inherit 10px !important}
</style>

… or …


<tag style="mystyle: inherit 10px inherit 10px !important">

Well the answer is simple, but can be confusing since its not as one might expect. If you use “inherit” as one of the values in your CSS then the entire style specified may be overridden by inheritance.

For example:


<style type="text/css">
div {margin: inherit 10px inherit 10px !important}
</style>

… or …


<div style="margin: inherit 10px inherit 10px !important">

… will be overridden by CSS present in stylesheets even though you may have specified !important or used the style inline, as in the second example.

So, if you want the inherited values to be carried through in these cases where your CSS is being overridden you can specify just the ones you want changed. In this case…


<style type="text/css">
div {margin-right: 10px; margin-left:10px;}
</style>

… or …


<div style="margin-right: 10px; margin-left:10px;">