eire web design home page contact eire-web design eire web design and development site map
stepping on in business
• CSS Hack !important

CSS Hack !important



In CSS is very easy to overwrite a rule you have created earlier, then you wonder why making changes to the rule doesn’t  apply to the page layout. 
One thing to know is the !important rule available since CSS1.
Adding !important after a command like this:

.div { margin-left: 5px;color:#ff0000!important;margin-left: 3px;}

will make sure that all browsers  will have a margin-left of 5px regardless of what appears after it, except IE (Internet Explorer)  which ignores the !important command gives a margin-left of 3px.

This can be very useful when you need to set relative margin as the display will differ from browser to browser.

IE, however, will respect the !important declarations if they are not in the same rule as below:

.div_font {color: red;!important;}
.div_font { color: blue; }

So whatever you asign this rule to the font color will be red not blue as in the second command. 

The first example above was a very useful CSS Hack for IE, however since IE7 has been released, the !important rule doesn’t have much effect any longer, as IE7 renders the page much like Firefox.

This entry was posted on Monday, October 15th, 2007 at 11:02 am and is filed under CSS. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


  • Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Links...

Chicklets...
  • http://www.eire-webdesign.ie/blog/feed/
    http://www.eire-webdesign.ie/blog/feed/
    Google Reader or Homepage
    Add to My Yahoo!
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    add to msn
    Add to My AOL
    Add to Technorati Favorites!
    pageflakes
    windows live