Wednesday, April 14, 2010

Conditional Comments HTML

Conditional comments are grate when targeting internet explorer, but when it comes to NOT targeting internet explorer they are a pain.  The code provided by Microsoft does not play well with HTML validators:

<![if !IE]>
    <p>This will not show in any version of IE</p>
<!endif]-->
<!--[if IE]>
    <p>This will only show in IE</p>
<!endif]-->


Fortunately, there is a work around.

<!--[if !IE]><!-->
    <p>This will not show in any version of IE</p>

<!--<!endif]-->
<!--[if IE]>
    <p>This will only show in IE</p>
<!endif]-->

By adding the tags in red, our code passes HTML validation and targets all browsers that are not Internet explorer.


Enjoy!


Rick Ramirez

No comments:

Post a Comment