Tuesday 12 January 2010

CSS trick for IE

I've just learned a very simple CSS trick that allows you assigning different attribute values if the page is rendered by IE. All you need to do is use '#' and '_' prefixes:

.myTestClass{
width: 5px; /* value used by all other browsers */
#width: 7px; /* value used by IE */
_width: 9px; /* value used by IE6 and older */
}


I don't think it's a part of the CSS official specification but it works ;)

3 comments:

Jaroslaw Dobrzanski said...

I've read that for IE7 an asterisk (*) should be used. You suggest a hash (#). Did you try both characters? Could you say if they both can be used for the same reason?

I'm referring to this article

Scott Roberson said...

I always use * for IE7 (and down), so if you want something different for IE6, you then have to follow that with a line preceded by a "_".

TrendGiveAfuck said...

If your code validates as strict doctype you won't need these browser specific "hacks".

Google "DOCTYPE strict" and "HTML validator."