Using the !important command.

Joined
9 May 2005
Posts
2,511
I have a question about the !important command that you can use after codes to make it definite. I always thought that if you placed it after something then it would only make that thing important and not anything else in its group.

It will probably be easier if I give an example.

a {
color: white!important;
font-size:16pt;
font-family: Calibri;
font-weight: 700;
}

Now with the above hyperlink code the !important tag is making everything important in the browser and not just the color. Although this only seems to happen in IE and not Firefox.

Is there anyway round this or am I doing it completely wrong?
 
dunno if it'll make a blind bit of difference, but I always use a space before the bang. I.e. 'white !important'

and the only place I use it is when using IE's shoddy, crappy, foul <!--[if IE]--> blocks, otherwise it's an indication you have improper classing/hierarchy etc. :)
 
and the only place I use it is when using IE's shoddy, crappy, foul <!--[if IE]--> blocks, otherwise it's an indication you have improper classing/hierarchy etc. :)

out of interest, what makes you say they're shoddy and foul? I find them incredibly useful!
 
Thanks for the suggestions guys, I tried first adding a space between the code and the !important but it made no difference.

I double checked my code and spotted my error, after sorting all is well without the need for that !important command.

Its funny that you can look and look at code and swear that its 100% correct and efficient and then after the third time looking it just pops out at you :p
 
No, I call them shoddy and foul because they are convention breaking (you can't use, for example, <!--[if opera]-->,) and also shoddy and foul because we (web-devs) have to use them in the first place, because IE is cack and doesn't comply to what the rest of the world does.
 
I think what he means to say is that if you need to use them, you're doing it wrong. ;)

Do you really believe that?

If it weren't for conditional comments, it would be so much more difficult to use new CSS techniques, selectors and stuff. The web shouldn't have to move as slow as the lowest common denominator, and developers should be able to take advantage of format improvements as and when they're released, not have to wait for rubbish old browsers to catch up.

They also allow me to spend as little time as possible fixing the ****ups that IE created by being "special".

for the record, I agree that it'd be nicer not to have to use them, but the world isn't perfect!
 
I think we should try and get every web developer in the world to send them angry emails, then they might, just might, do something about it.
 
Do you really believe that?

Depends on how you look at it.
If the page is accessible and works well in all the browsers, it can be said that it's done right regardless of the code.

Personally though, I just wouldn't be happy having to rely on !important because if my targeting is correct, I shouldn't need to use it. I'm guilty of using it on rare occasion but as a general rule, I try not to.
 
knowing what you were talking about, I agree! I don't like using !important but it's very useful if you're working with a stylesheet that looks like it was put together by a 5-year-old and you haven't got time to refactor it.
 
Back
Top Bottom