0

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

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
leora
  • 188,729
  • 360
  • 878
  • 1,366

2 Answers2

3

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.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • 1
    It might be even easier to use ` – David Thomas Dec 12 '10 at 17:54
  • @David: Don't you mean `if gte IE 7`? – BoltClock Dec 12 '10 at 17:59
  • @BoltClock, um, why: yes; yes, I do... =D – David Thomas Dec 12 '10 at 18:00
  • 1
    I don't know about anyone else, but I'm intrigued as to the reason for the down-vote... – David Thomas Dec 12 '10 at 18:15
  • @BoltClock: but not *explained*, which is the part that always irritates me. I don't *mind* being down-voted, but without explanation there's no opportunity to *learn* from it. Which is a completely wasted opportunity. – David Thomas Dec 12 '10 at 18:35
  • @David: I understand. At least if someone explains their downvote, I can tell if it's a good reason... or a stupid reason, like for [this other answer of mine :)](http://stackoverflow.com/questions/4352971/does-foreach-work-for-non-numerical-array-keys/4352974#4352974) – BoltClock Dec 12 '10 at 18:38
  • @David: Oh, he's well-known around these parts. – BoltClock Dec 12 '10 at 18:44
  • I was the downvoter, and did so because I figured that the close comment method BoltClock used was unneeded when there was a simpler way. I undid the downvote only because of the comment on my answer. @David: I think that going around explaining downvotes is counter productive. More times than I can count I've seen people that firmly believe that downvoting is **always** wrong. Don't pay attention to *a* downvote, unless by reading the other answers you can't understand what might be wrong. Also, http://meta.stackoverflow.com/search?q=downvotes+explain – Esteban Küber Dec 12 '10 at 20:07
  • @voyager, the point of a down-vote is to make the point that an answer is unhelpful. Explaining in what way the answer is unhelpful gives everyone a chance to learn, which is, surely, the point of Stack Overflow? – David Thomas Dec 12 '10 at 20:14
0

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.

Esteban Küber
  • 36,388
  • 15
  • 79
  • 97
  • While that works for IE, it causes the HTML to become invalid. – BoltClock Dec 12 '10 at 18:21
  • @BoltClock: it's the recommended way by MS, yet it's a valid point. Keep in mind that if you are having hacks for IE6 your code most likely won't be validating anyway. – Esteban Küber Dec 12 '10 at 18:31