htmlcsscss-cascade

More important than !important (a higher level !important)?


The title says most of it. Is there a CSS keyword which overrides !important at one higher level or is there some feature like this planned in any newer CSS spec?

Of course, I know that !important is a bit likely to be used by noobs and that in many cases it is not the best way to go as stylesheets may really suck if badly written. However, sometimes it's useful and even needed.

The strongest style in CSS I can think of is an inline style with !important like this:

<span id="bluebeaver" style="color: red !important;">I am a happy blue beaver</span>

Now let's assume that I cannot edit the HTML and must modify the style from an external stylesheet.

It would be really great to have something like:

#bluebeaver {
    color: blue !important 2;
}

If they had levels for it like for instance with z-index.

Is there any solution to this or anything planned with newer CSS specifications? So far I did not find anything.

Can you show a CSS solution to override an !important inline style or is there definitely no possibility?


Solution

  • No, there is no keyword or other way to make a declaration more important than !important. There is no known activity to change this.

    In general, it is possible to override a declaration that has !important by using a rule that also has it and that has higher specificity. However, a declaration in a style attribute has, by definition, higher specificity than any other author declaration. The only way to defeat it is in CSS is to use a user style sheet with !important.

    There are non-CSS solutions, but they are rather obvious, such as using JavaScript to simply remove or modify the style attribute.