Correct conditional comments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamalton
    New Member
    • Feb 2007
    • 93

    Correct conditional comments

    Hi, I'm putting some conditional comments into a page to stop Internet Explorer 6 from being the evil piece of sh!$ that it is.

    I want one stylesheet for IE 6 and another for all other browsers.

    So...
    [HTML]
    <!--[if IE 6]><link href="ie6.css" type="text/css" rel="stylesheet " /><![endif]-->[/HTML]That's easy enough. But then for all the other browsers, Microsoft suggest this:[HTML]<![if !IE 6]><link href="normal.cs s" type="text/css" rel="stylesheet " /><![endif]>[/HTML]But surely that's not really valid? Surely a comment needs to start with[HTML]<!--[/HTML]and end with[HTML]-->[/HTML]So I am thinking that this is a 'correct' way of doing it...[HTML]<!--[if !IE 6]--><link href="normal.cs s" type="text/css" rel="stylesheet " /><!--[endif]-->[/HTML]So my question is, does that work? To me it is more valid, in a W3C sense. But I don't have a computer with IE6 (or any version of IE) on it, so I can't test to see if it will do the job. If someone could test it, or if someone knows whether or not it will work, that'd be great.

    Thanks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Yes, that should work and you're also correct about the original suggestion beig invalid - see link.

    Comment

    • adamalton
      New Member
      • Feb 2007
      • 93

      #3
      Thanks.. I had a search on Google for an explanation like the one in your link, but hadn't found one.

      For anyone else reading this, note that according to the linked page above the valid version should be:[HTML]<!--[if !IE 6]--><link href="normal.cs s" type="text/css" rel="stylesheet " /><!--<![endif]-->[/HTML]

      (an extra <! in the second comment). Not sure if it makes any difference.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I think what they've done is add the beginning comment to the suggested version.

        Since the suggested version by Microsoft is the "safer" (though invalid) method, there's no guarantee that this will work in future versions (see http://en.wikipedia.org/wiki/Conditi...tional_comment).

        Comment

        Working...