!important in css

Discussion in 'HTML' started by Paul F. Johnson, Nov 25, 2003.

  1. Hi,

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

    TTFN

    Paul
    Paul F. Johnson, Nov 25, 2003
    #1
    1. Advertising

  2. Michael Wilcox, Nov 25, 2003
    #2
    1. Advertising

  3. Paul F. Johnson wrote:

    > 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.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
    Toby A Inkster, Nov 25, 2003
    #3
  4. Toby A Inkster <> wrote:

    > 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.)

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Nov 25, 2003
    #4
  5. Jukka K. Korpela wrote:

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

    >
    > 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.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
    Toby A Inkster, Nov 25, 2003
    #5
  6. Toby A Inkster:

    >>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.


    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.

    --
    Bertilo Wennergren <> <http://www.bertilow.com>
    Bertilo Wennergren, Nov 25, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Important Newsgroup Virus Information

    Kevin Spencer, Sep 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,380
    William Ryan
    Sep 2, 2003
  2. Alex Yu
    Replies:
    1
    Views:
    1,378
    Tom Vande Stouwe MCSD.net
    Sep 3, 2003
  3. Yair Cohen
    Replies:
    0
    Views:
    2,022
    Yair Cohen
    Sep 4, 2003
  4. Miha Markic

    Install this important update

    Miha Markic, Sep 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    451
    Martin Robins
    Sep 27, 2003
  5. Spartanicus
    Replies:
    2
    Views:
    933
    xangelusx
    Aug 25, 2006
Loading...

Share This Page