Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > !important in css

Reply
Thread Tools

!important in css

 
 
Paul F. Johnson
Guest
Posts: n/a
 
      11-25-2003
Hi,

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

TTFN

Paul
 
Reply With Quote
 
 
 
 
Michael Wilcox
Guest
Posts: n/a
 
      11-25-2003
Paul F. Johnson <paul@spammersahoy!.co.uk> wrote:
> What does it mean when you have a stylesheet with !important after
> one of the parameters?


http://www.w3.org/TR/REC-CSS2/cascad...mportant-rules
--
Michael Wilcox
mjwilco at yahoo dot com
Essential Tools for the Web Developer - http://mikewilcox.t35.com


 
Reply With Quote
 
 
 
 
Toby A Inkster
Guest
Posts: n/a
 
      11-25-2003
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

 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      11-25-2003
Toby A Inkster <(E-Mail Removed)> 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


 
Reply With Quote
 
Toby A Inkster
Guest
Posts: n/a
 
      11-25-2003
Jukka K. Korpela wrote:

> Toby A Inkster <(E-Mail Removed)> 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

 
Reply With Quote
 
Bertilo Wennergren
Guest
Posts: n/a
 
      11-25-2003
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 <(E-Mail Removed)> <http://www.bertilow.com>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Layout question - how to duplicate a table layout with CSS Eric ASP .Net 4 12-24-2004 04:54 PM
confused - html validates, css validates but validate css from the html causes errors Titus A Ducksass - AKA broken-record HTML 6 11-15-2004 12:59 PM
Set CSS property equal to another CSS property? Noozer HTML 10 10-13-2004 09:20 PM
Is there a way to set the a CSS property to be explicitly the same as another CSS property? Joshua Beall HTML 1 12-10-2003 07:21 PM
print.css and screen.css tom watson HTML 1 09-09-2003 02:48 PM



Advertisments