Skip to main content

Importance of !important in CSS

Do you know What does !important mean in CSS?, an "!important" declaration (the keywords "!" and "important" follow the declaration) this takes high precedence over a normal declaration. And can be framed in this way, this means that the styles are applied in order as they are read by the browser.

CSS it 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. But in CSS1, this is in other way round - Author "!important" rules took precedence over User "!important" rules.


For Example:
User's Style Sheet:
    1: <style> 
    2:   p{font-size: 2em !important;} 
    3:   p{font-style: italic;} 
    4: </style>

Author's Style Sheet:
    1: <style> 
    2:   p{font-size: 3em;} 
    3:   p{font-style: normal;} 
    4: </style> 

If you see in the above instance, the first rule in the User's Style Sheet has "!important" declaration, which will overrides the first rule in the Author's Style Sheet. And if you observe for the second rule in User's Style Sheet it does not contain "!important" so this will be ruled out because here second rule in the Author's Style Sheet has got high preference so the HTML will render by taking size as "p{font-style: normal;}"

If you would like to know more on this, then check with the w3 site:
w3.org and move to the section called "6.4.2 !important rules"

Comments

Popular posts from this blog

Why SharePoint 2007?

It is rare for a technology product to attract as much attention as SharePoint has in recent years. The industry has historically paid little attention to new product suites, particularly those related to web design. SharePoint products and technologies, however, have managed to excite and rejuvenate industry followers, causing them to take notice of the ease of use, scalability, flexibility, and powerful document management capabilities within the product. A number of organizational needs have spurred the adoption of SharePoint technologies. Some of the most commonly mentioned requirements include the following: A need for better document management than the file system can offer —This includes document versioning, check-out and check-in features, adding metadata to documents, and better control of document access (by using groups and granular security). The high-level need is simply to make it easier for users to find the latest version of the document or documents they need to do th...

Comma separated list of values of single Database table field

Many times you need to create a comma seperated list of values in a table. Here is a line of T-SQL solution to get comma separated list of values of single field of a database table. DECLARE @commaSeparatedVal AS VARCHAR(MAX); SELECT @commaSeparatedVal = ISNULL(@commaSeparatedVal +',','') + CONVERT(VARCHAR,[SKU]) FROM PRODUCT PRINT @commaSeparatedVal