Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 11th, 2008, 05:51 AM
Registered User
Join Date: Feb 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default CSS problem

Hi there,
I have seen many site designed with CSS and in that file many of the styles mentioned "!important" in it like:
font-weight: bold !important;
I just want to know that what is the meaning of "!important" here? Is this matter to boldness of text or is this something else?

Thanks in advance.

  #2 (permalink)  
Old March 11th, 2008, 02:28 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

My understanding is that this flags a rule as "important" such that other rules should not override the rule's setting for the element style that matches the selector. The styles rules applied to an element are based on the cascade order of the styles (hence the name Cascading Style Sheets) as well as the granularity of the selector.

For example, if you have this style rule:

        background-color: green;

and then you have this rule later in processing (whether it's in another style sheet or the page itself):

        background-color: red;

All your TD elements will have the background color set to red because the selector "TABLE TD" is more defined than just "TD" even though they ultimately refer to the same elements (because TD will always be inside of a TABLE element). CSS doesn't consider the *logic* rules of elements (i.e. TD inside of TABLEs) it just cares about the actual structure. A more defined selector will prevail over a less defined one.

So now we add "!important" to the first rule:

        background-color: green !important;
        background-color: red;

Now our TD elements will be green.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Css formatting problem beetle_jaipur CSS Cascading Style Sheets 2 June 5th, 2009 07:16 AM
problem with css menus kanoorani CSS Cascading Style Sheets 0 February 16th, 2008 07:44 AM
CSS Menu problem twc02 CSS Cascading Style Sheets 24 March 11th, 2005 11:01 AM
CSS comments problem Groundhog1248 CSS Cascading Style Sheets 2 January 20th, 2005 09:23 AM
CSS Problem Ben Horne HTML Code Clinic 2 November 10th, 2003 05:31 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.