IE Conditional Comments

by jp on June 20, 2004

Even that IE has terrible CSS support it still have one nice little hack to help develop CSS’s and other stuff too.
Instead using browser detect in JavaScript there is Conditional Comments to do same trick.

Syntax
<!–[if IE]><style type=”text/css”> /*<![CDATA[*/ body { color: #000000; } /*]]>*/ </style> <![endif]–>

Applied By

* Win IE 5.0 – 6.x

<!–[if ( ! )* ( comparison )* IE ( version number )* ]> HTML content to parse if the condition is true goes here <![endif]–>

By wrapping an embedded stylesheet in conditional comments, you can make the styles apply only to IE5+ on Windows. Below are a number of ways to write conditional comments to target specific combinations of IE5+ browsers:

<!–[if gte IE 5]> IE 5.0 – 6.x

<!–[if IE 5]> IE 5.0

<!–[if IE 5.5000]> IE 5.5

<!–[if IE 6]> IE 6.0

<!–[if gte IE 5.5000]> IE 5.5 – 6.x

<!–[if lt IE 6]> IE 5.0 – 5.5

About Conditional Comments

One comment

Not having to filter for browsers would be nicer though :)

by Helen on 26 July, 2004 at 1:20 pm. #