IT Community - Software Programming, Web Development and Technical Support

!important rule in CSS

This is a discussion on !important rule in CSS within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all, Can anyone explain about, what is the purpose of using !important rule in CSS...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-29-2007, 05:52 AM
velhari velhari is offline
D-Web Programmer
 
Join Date: Mar 2007
Location: Chennai
Posts: 67
velhari is on a distinguished road
Send a message via AIM to velhari
Question !important rule in CSS

Hi all,
Can anyone explain about, what is the purpose of using !important rule in CSS
__________________
Regards,
VELHARI
I am not totally useless. I can be used for a bad example
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-29-2007, 06:03 AM
KiruthikaSambandam KiruthikaSambandam is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 332
KiruthikaSambandam is on a distinguished road
Default Re: !important rule in CSS

Hi

! important

Rules can be designated as important by specifying ! important. A style that is designated as important will win out over contradictory styles of otherwise equal weight. Likewise, since both author and reader may specify important rules, the author's rule will override the reader's in cases of importance.

A sample use of the ! important statement:

BODY { background: url(bar.gif) white;
background-repeat: repeat-x ! important }

ThankQ
KiruthikaSambandam
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-29-2007, 06:12 AM
sathian sathian is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 252
sathian is on a distinguished road
Default Re: !important rule in CSS

!important CSS rule


Cascading Style Sheets cascade. This means that the styles are applied in order as they are read by the browser. The first style is applied and then the second and so on. What this means is that if a style appears at the top of a style sheet and then is changed lower down in the document, the second instance of that style will be the one applied, not the first. For example, in the following style sheet, the paragraph text will be black, even though the first style property applied is red:

p { color: #ff0000; }
p { color: #000000; }

The !important rule is a way to make your CSS cascade but also have the rules you feel are most crucial always be applied. A rule that has the !important property will always be applied no matter where that rule appears in the CSS document. So if you wanted to make sure that a property always applied, you would add the !important property to the tag. So, to make the paragraph text always red, in the above example, you would write:

p { color: #ff0000 !important; }
p { color: #000000; }

User Style Sheets


However, the !important rule was also put in place to help Web page users cope with style sheets that might make pages difficult for them to use or read. Typically, if a user defines a style sheet to view Web pages with, that style sheet will be over-ruled by the Web page author's style sheet. But if the user marks a style as !important, that style will overrule the Web page author's style sheet, even if the author marks their rule as !important.

This is a change from CSS1 to CSS2. In CSS1, author !important rules took precedence over user !important rules. CSS2 changed this to make the user's style sheet have precedence.

ThankQ
Sathian.K
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-01-2007, 01:57 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: !important rule in CSS

CSS tries to create a balance of power between author and user style sheets. By default, rules in an author's style sheet override those in a user's style sheet.

However, for balance, an "!important" declaration takes precedence over a normal declaration. Both author and user style sheets can contain "!important" rules, but user "!important" rules override author "!important" rules.

Note: In CSS1, it works the other way: Author "!important" rules took precedence over user "!important" rules.

If you, in your style sheet want to mark something as important, use the following code:

P { font-size: 18pt ! important }
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is XML important? scheme XML and SOAP 5 03-21-2008 09:42 PM
Why is XML such an important development? leoraja8 XML and SOAP 1 09-04-2007 08:13 AM
Explain ACID rule of thumb for transactions. anbuchezhians VB.NET Programming 1 07-27-2007 02:47 AM
What are three rule to create good passwords? vadivelanvaidyanathan Database Support 1 07-17-2007 12:41 AM
Important: ASP.NET Vulnerability Gopisoft ASP and ASP.NET Programming 2 03-30-2007 03:08 AM


All times are GMT -7. The time now is 10:59 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0