简体   繁体   中英

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. 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 ??

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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