开发者

Use a stylesheet when NOT IE

When i use this code

<!--[if IE 6]>
<link rel="stylesheet" href="ie6.css" type="text/css" />
<![endif]-->

<!--[if !IE]>
<link rel="stylesheet" href="not_ie.css" ty开发者_StackOverflow中文版pe="text/css" />
<![endif]-->

IE 6 does correctly use the specified stylesheet but all other browsers ignore both when they should be using the one that basically states, use this stylesheet if you are not IE.

Any ideas?


The not IE conditional comment is a bit of a hack, and is therefore written slightly differently from when you are targeting IE.

<!--[if !IE]><!-->
<link rel="stylesheet" href="not_ie.css" type="text/css" />
<!--<![endif]-->

Non-IE browsers will read this as they ignore the conditional comments completely and the comment is considered closed with the added extras. IE will read this as a "not IE" conditional and avoid calling the stylesheet.


Only IE supports conditional comments. So FF, Chrome, Safari, Opera, etc will ignore these comments.

Your best best would to be to make one stylesheet for the other browsers and use the conditional comments to set up a separate stylesheet for IE.


That's because you've commented it out. The correct way to include a style for "not-ie" would be like this:

<!--[if !IE]><!-->
<link rel="stylesheet" href="not_ie.css" type="text/css" />
<!--<![endif]-->

EDIT: Of course it's better to have all the standard css in a file that is allways included, and let the ie specific css override. But this could be the fastest way to include some style that all other browsers handle but ie doesn't and that is hard to properly change back to the default for ie.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜