简体   繁体   English

您如何获得“ IE 6条件注释”的工作?

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

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. 我现在正尝试放置特定于ie6的变通办法,因此,如果浏览器不是IE 6,我将仅尝试使用此div。因此,如果它的IE7、8,firefox和chrome,我希望此行能够显示。 I tried this but it doesn't seem to work in Firefox or Chrome. 我尝试了此操作,但它似乎在Firefox或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 ?? 在html文件中是否有任何“如果不是IE6的话”条件注释?

To target any IE except IE6, you use the ! 要定位除IE6以外的任何IE,请使用! 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: 要定位除IE6之外的任何IE 以及所有其他浏览器 ,您需要特殊的语法来突破条件注释,以便其他浏览器可以读取和解析其中的HTML,而不是将整个块视为一个注释:

<!--[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. 但是,它是无效的HTML,因此为了保持文档的有效性,您应该改用上述语法。

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. IE以外的浏览器将<!--[if !IE 6]><div id="hd1" class="header headerNotIE6"><![endif]-->作为常规注释,因此它们永远都不会看看里面的div

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM