Hello there... Sometimes when I review other ppls CSS styles (my kinda way learning things ), I keep coming up with some kind of !important comment... basiclly in css hacks... what does it means? why is it used? thank you.
It alerts the Browser that attention is required. In this example: width:160px !important; /*moz width*/ width:170px; /*IE width*/ it sets the div width for FF at 160px(plus padding) and IE at 170px (with padding) The div is then rendered the same in both browsers.
Funny, I thought it was the other way around: the IE looked at !important. It always confuses me because to me ! means "not". I guess not so in html.
Not really for "attention", it's used to set precedence. Colbyt, I wouldn't use a hack to demonstrate things like this. Stommepose, it is IE that doesn't support this value.
Yes, it is used to set precedence in compliant browsers. Basically it overrides everything, including user stylesheets. Use it with care, it often violates usability standards.
When you say "usability", are you sure you are referring to the correct term? If so, how does it do so. The negatives of !important may be confusion for developers during maintenance of CSS and lack of browser support (namely IE). Nothing to do with usability for the end user.
I find "!important" usable when I'm making forms especially if I want to have input be aligned perfectly
Adding !important to a style declaration will ensure that declaration overrides all other style declarations applied to the same element. So, if you use this CSS code: p { color: blue !important; }, then all of your paragraphs will be blue. Even paragraphs with a class or id indicating a different color, and even those with an inline style declaration. qube99, it was only in CSS1 that !important declarations overrode reader style sheets. Reader stylesheets should override !important in CSS2 browsers.
Thanks for pointing the CSS2 out. I wonder which browsers actually do it the new way? Accessibility standards are for handicapped folks, some users will override your stylesheets and use their own because of vision problems. This is where !important can cause trouble.
!important is supported by most browsers, including IE7 in standards mode only. It does not work in IE <6. Tested FF2, Opera, IE6, IE7, Safari.
Way back when I was first learning CSS, !important confused the HELL out of me... NOT because I couldn't grasp how it worked, but because it was PAINFULLY obvious nobody involved with programming was involved in it's creation. Why do I say this? It's the same problem Stomme has with it: What does ! mean in most AT&T syntax programming languages? It means 'NOT'. !important... Not important? Shouldn't that really have the opposite effect it does? I know it doesn't, but the programmer in me cringes every time I see it.
It only takes one look at a reference and a DIY example to see this is not the case, it's not that confusing. Maybe an @ could have been used instead so it can be consistent with the other keywords such as import and media, oh well, who cares, not like there are many practical uses for !important anyway, it usually causes more problems than it solves.
Or ends up being used for some garbage 'silver bullet' fix for a deeper underlying problem that the original coder is too lazy to fix. Hence the reason you see it so much on sites where the person doing the CSS has no access to the 'master' CSS or HTML or lacks the knowledge to make those changes - when the HTML in question is total garbage. See mySpace, Blogger, Xanga, most wordpress templates, HTML set up from WYSIWYGS like Frontpage or Dreamweaver, etc, etc.