How do you get “IE 6 conditional comments” working?

孤者浪人 提交于 2019-12-02 08:34:36
BoltClock

To target any IE except IE6, you use the ! operator:

<!--[if !IE 6]>
    <div id="hd1" class="header headerNotIE6">
<![endif]-->

To target any IE except IE6 as well as all other browsers, you need special syntax to break out of the conditional comments so other browsers can read and parse the HTML inside, instead of seeing the entire block as one comment:

<!--[if !IE 6]><!-->
    <div id="hd1" class="header headerNotIE6">
<!--<![endif]-->

The original syntax as shown in voyager's answer, known as downlevel-revealed syntax, lacks the extra comment delimiters. However, it is invalid HTML, so to maintain document validity you should use the above syntax instead.

What you have to use is

<![if !IE 6]>
  <div id="hd1" class="header headerNotIE6">
<![endif]>

Browsers other than IE see <!--[if !IE 6]><div id="hd1" class="header headerNotIE6"><![endif]--> as a normal comment, so they don't ever get to see the div inside.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!