Search code examples
htmlinternet-explorerconditional-comments

(!IE) Problems with Blocking Code from IE


I have (once again) been enhancing my template for a school site. However, I have run into another problem. I have noticed that the navigation bar does not render properly in any Internet Explorer version prior to IE9 (to be expected). I had seen the use of the !IE tag around the web and tried replicating it on my design. However, once implemented, every browser stopped showing that piece of code.

<!--[if !IE]>
    <li><p>&nbsp;&nbsp;</p></li>
    <li><img src="vp-global-logo.gif" />
<![endif]-->

I also tried:

<!--[if gte IE 9]>
    <li><p>&nbsp;&nbsp;</p></li>
    <li><img src="vp-global-logo.gif" />
<![endif]-->

How would I get this to work? Is there any alternative method without making the site too slow?


Solution

  • You need to terminate the conditional comments with a special syntax:

    <!--[if !IE]><!-->
        <li><p>&nbsp;&nbsp;</p></li>
        <li><img src="vp-global-logo.gif" />
    <!--<![endif]-->
    

    This prevents IE from displaying the HTML while other browsers get to see it, treating the if and else as regular HTML comments.