问题
I'm using the following IE conditional statement to load an IE-specific stylesheet. The statement works in IE 7, 8 and 9 Compatibility View. However, when I viewed the page in plain IE 9, the page was empty. I inspected it in developer tools, and it appears as though the conditional statement never closes, effectively commenting out the rest of the page.
<!--[if lt IE 9]><link xmlns="" rel="stylesheet" href="http://colum.edu/Site_Files/localist/css/ie.css" /><[endif]-->
After a decent amount of hair-pulling, I finally figured out that if I add a space before the brackets for the conditional comment, it comment works in IE 9:
<!-- [if lt IE 9]><link xmlns="" rel="stylesheet" href="http://colum.edu/Site_Files/localist/css/ie.css" /><[endif]-->
The only difference is that there is a space between comment and the conditional statement...
<!--[if lt IE 9]> vs <!-- [if lt IE 9]>
I can't figure out why on earth this is happening. Again, it only happens is "Browser Mode: IE9" not "Browser Mode: IE9 Compatibility view" with "Document Mode: IE9 standards". (I realize that the simplest solution is to add the space. However the real page lives on a hosted service, and I'm limited in what I can edit.) Anyways, here are some examples:
Not working: http://dev.ashramcreative.com/ccc/localist/ie9.html
Working: http://dev.ashramcreative.com/ccc/localist/ie9-space.html
回答1:
I just ran into the same thing; and adding the space before the conditional fixed IE9 in browser mode.
After reading this post I was able to determine that a meta tag was to blame.
After I corrected the meta tag (in my case meta http-equiv=content-type
), IE9 in browser mode worked correctly without the space.
However, in your case it appears as though the <[endif]-->
should be <![endif]-->
来源:https://stackoverflow.com/questions/9743385/conditional-comment-in-ie-9-space-between-comment-and-conditional-statement