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

怎甘沉沦 提交于 2019-12-02 14:44:29

问题


i have this markup which works fine:

<div id="hd1" class="header headerNotIE6">

i am now trying to put a ie6 specific workaround so i am trying to only have this div if the browser is not IE 6. So i want this line to hit if its IE7, 8 and firefox and chrome. I tried this but it doesn't seem to work in Firefox or Chrome.

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

is there any "if everything but IE6" conditional comment that works in an html file ??


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4423000/how-do-you-get-ie-6-conditional-comments-working

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