Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE ignores !important tag in css [closed]

Recently I came across a wierd thing in IE.

It ignores a '!important' tag for CSS attributes.

Does anyone have a workaround for this, except putting it directly as a style attribute inside the DOM?

I do not want to go into the DOM and put styling attributes in it.

like image 491
Neeraj Avatar asked May 25 '11 15:05

Neeraj


People also ask

How do you stop important in CSS?

To avoid using ! important , all you need to do is increase specificity. In your case, both of your selectors have identical specificity. The issue is most likely caused by your media query being placed before your "Normal CSS", and thus getting overridden.

Is it good practice to use important in CSS?

The use of ! important is considered an anti-pattern and bad practice. ! important overrides all other declarations and makes the CSS code more difficult to maintain and debug.


1 Answers

I've found the !important tag will not work in a style if it has previously been used on the style that you are trying to overwrite/update.

For example, if you have:

.example{
color:#ff0000 !important;
}

And, say for example, if your using Media Queries and tell the style to change upon the browser being reduced in size:

.example{
color:#fff !important;
}

The secondary colr #fff won't take affect because of the !important assigned to the color #ff0000.

Just an observation/thought.

It's pretty hard to guess what is causing the issue. For the users of SO to really help you, you will have to either supply a live link, sample code on jsfiddle.net or post your HTML and CSS in the question.

like image 117
Dan Avatar answered Sep 21 '22 13:09

Dan