Connecting Tech Pros Worldwide Forums | Help | Site Map

Correct conditional comments

Member
 
Join Date: Feb 2007
Posts: 94
#1: Oct 14 '08
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.css" 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.css" 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's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Oct 14 '08

re: Correct conditional comments


Yes, that should work and you're also correct about the original suggestion beig invalid - see link.
Member
 
Join Date: Feb 2007
Posts: 94
#3: Oct 14 '08

re: Correct conditional comments


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.css" type="text/css" rel="stylesheet" /><!--<![endif]-->[/HTML]

(an extra <! in the second comment). Not sure if it makes any difference.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Oct 15 '08

re: Correct conditional comments


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).
Reply