Conditional Comment: All Browsers Except IE6 and Lower

I was wondering if it were possible to have a conditional comment that says show to all browsers, save for anything lower than IE7.

I tried this, but didn’t work: <!–[if !(IE)|(gte IE 7)]>

Is there a way? I’m trying different patterns and so far can’t see anyting show in firefox.

Cheers
Ryan

Only Microsoft programs understand those conditional comments so you have to code them so that what you don’t want other browsers to see is inside the <!-- –> and what you do want other browsers to see is not inside the comment.

If I understand correctly what you’re asking, then you can make use of downlevel-revealed conditional comments: http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx#dlrevealed.

In fact, I used something like this for the SPF Pure HTML & CSS comp. For IE6 I’m not bothering with fixes or hacks anymore, and since JS is out the door, I just let my beautiful CSS-nude semantic mark up be :slight_smile: And it suits me just fine.

It’s time to let go of IE6, IE9 is already taking over big time. And it’s time to exploit a better CSS: + selector, :hover for anything, w/o thinking first how can you patch it with JS libraries. I mean, we talk about CSS3 but we still don’t see a heavy serious COMPLETE use of decades old CSS 2.1, and we still use JS to patch weak CSS implementations like it’s 1997. Basta!

The page below will have red background for all browsers, except IE1-IE6. My personal COMPLETE graceful degradation for IE6 :slight_smile: The CGD movement.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" dir="ltr"><head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="content-language" content="en">
    <title>Only IE 7 and up. And the rest.</title>
    <meta name="author" content="noonnope - Mitic&#259; U.">
    <meta name="copyright" content="noonnope - Mitic&#259; U.">
    
<![if !(lt IE 7)]>
    <style type="text/css">
    
      body {
          background:red;
        }

    </style>
<![endif]>

</head><body>

  <h1>If it's red screen then it's not IE1-IE6!</h1>

</body></html>

Thanks for the feedback. I sort of did an ifstatement that just changed the style display of the footer I was trying to have to “none” if IE and less than 7.

Ryan

<![if !(lt IE 7)]>
[…]
<![endif]>

means […] will NOT apply to IE less than IE 7, but it will apply to IE7+ and ALL the other browsers, including Firefox. Isn’t that what you wanted?

So, if you have style you DO NOT want it applied to IE6-, you put

<![if !(lt IE 7)]>

<![endif]>

around it.

<![if !(lt IE 7)]>

<![endif]>

will be recognized only by IE-family browsers: IE6- will not apply the part in between, IE7+ will apply it, and those two lines will be indiferent to the rest of the browsers: FF, Ch, Op, Saf etcetera, as they will apply the part in between, like IE7+, since it’s not a comment, the comment feature that is the downside for using the other IE CC: <!–[if … endif]–>.

Unfortunately the Microsoft downlevel revealed comments are invalid and will not pass validation. There is however an alternative that is valid and goes like this:


<!--[if gte IE 7]><!-->
  <p>This is shown in downlevel browsers and IE7 or later.</p>
<!--<![endif]-->


More info here.

It’s a false positive, so to speak, and it’s not an error, strictly speaking, much like -moz, -webkit CSS aren’t. And the one I appreciate and tolerate, like <xml> element, that I, once again, feel it should have been a natural solution for many, many problems. I almost love <xml> and feel so sad it’s not standard, not even in these new specs.

I prefer to use less:
<![if !(lt IE 7)]>

than more
<!–[if gte IE 7]><!–>

which, by the way, is a dirty trick. Maybe clever, but dirty. I don’t like this “smartiness” in my code.

It’s for the same reason I don’t agree with *+ html, for example, and I prefer a clean CC. I’m not making my omelet mixing rotten eggs with good ones. My unclean code on a side, my clean code on the other side. But it’s a personal choice. :slight_smile:

Yes I only mentioned it for completeness and in case they were needed to validate. It’s of little consequence otherwise I agree.