开发者

IE7 conditional CSS comments not working

I have IE8 installed on my Windows 7 machine and I'm using the developer tools to display pages with the IE7 browser mode.

I want to add a conditional stylesheet for IE7 but it's not working. The path is correct, so my guess, at this point, is that the IE7 browser mode doesn't actually render fully as IE7.

       <!--[if IE 7]>
     开发者_运维百科      <link rel="stylesheet" type="text/css" href="http://example.com/media/IE7/ie_splash.css" />
       <![endif]-->

Any thoughts or suggestions?


I've done a quick check on Windows XP and can't replicate this - you could try:

<html>
<body>

<!--[if IE 6]>
I am IE 6
<![endif]-->

<!--[if IE 7]>
I am IE 7
<![endif]-->

<!--[if IE 8]>
I am IE 8
<![endif]-->

</body>
</html>

And see what version it renders in your browser. For me, toggling to IE7 renders "I am IE 7".


I also got this problem and by specifying the two conditional comments I was able to solve it.

First, the usual conditional comment to load the css file for IE 7

<!--[if IE 7]>
           <link rel="stylesheet" type="text/css" href="http://example.com/media/IE7/ie_splash.css" />
<![endif]-->

Second, you need to specify your style sheet for all other browsers with the !IE syntax. So IE stop rendering your style sheet that you prepared for other browser.

<!--[if !IE 7]><!-->
    <link rel="stylesheet" media="all" href="style.css" />
<!--<![endif]-->

here style.css is your original stylesheet that you are using for other browsers and don't want IE to use it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜