!important in css

P

Paul F. Johnson

Hi,

What does it mean when you have a stylesheet with !important after one of
the parameters?

TTFN

Paul
 
T

Toby A Inkster

Paul said:
What does it mean when you have a stylesheet with !important after one of
the parameters?

Since CSS2, "!important" has only really had any meaning in user (i.e. not
author) style sheets.

Under CSS 1, styles were applied with the following priorities:

1. (Highest:) Author's "!important" declarations
2. User's "!important" declarations[1]
3. Author style sheet
4. User style sheet
5. (Lowest:) Browser default styles

So if the user set:
body { color: blue !important; }

and the author:
body { color: red; background-color: white; }

Then the browser would set the foreground colour to blue (user's
"!important" declaration) and the background colour to white (author's
style sheet).

That's what the "C" in CSS is all about: Cascading. If a style isn't
specified in the author's "!important" declarations, it "cascades" to the
user's "!important" declarations and then the rest of the author's style
sheet declarations, blah, blah.

This gave CSS an advantage that earlier style sheet languages didn't have:
the ability to work out a compromise between user and author settings.

[1] Under CSS 2 they swapped 1 and 2 around.
 
J

Jukka K. Korpela

Toby A Inkster said:
Since CSS2, "!important" has only really had any meaning in user (i.e. not
author) style sheets.

I can't quite parse the statement, but anyway, the !important specifier has
a defined meaning both in user style sheets and in author style sheets.
Whether authors should use it is debatable, but they surely can. And
although an author's CSS rule does not gain any more power in competition
(cascade) with user style sheets - it wins normal user rules and loses to
!important user rules whether it itself has !important or not - the
!important specifier is still relevant in competition with other author
style sheets. (For example, a company's style sheet might say something, and
employers might be required to use them, i.e. <link> them, but still
overrule them with !important rules in some cases.)
 
T

Toby A Inkster

Jukka said:
I can't quite parse the statement

"Since" is used to mean "in the time after", not "because".
but anyway, the !important specifier has a defined meaning both in
user style sheets and in author style sheets.

"Meaning" was possibly a poor choice of word. "Usefulness" might have been
better.
 
B

Bertilo Wennergren

Toby A Inkster:
"Meaning" was possibly a poor choice of word. "Usefulness" might have been
better.

I often use it as a temporary means to find if a rule doesn't work just
because it's overridden by some other rule somewhere, or if I'm just
doing something wrong: I add an "!important", and if the rule then
suddenly works, then I know it's beause some other rule takes precedent.
If it's just a quick job then I might simply leave the "!important" in
and be done with it. So it's quite useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top