CSS for IE 8 Only

梦想与她 提交于 2019-12-02 20:08:35

问题


I need to style some items for only IE 8. If I do this:

<!--[if IE 8]><link rel="stylesheet" href="mystyleIE8.css" type="text/css" media="screen, projection"/><![endif]-->

and then I do:

<!--[if IE 7]><link rel="stylesheet" href="myStyleIE7.css" type="text/css" media="screen, projection"/><![endif]-->

What will happen? I found this link to a previous SO question which implied that <!--[if IE 8]> means "If IE 8 or lower". Does this mean that using <!--[if IE 8]> will overwrite all <!--[if IE 7]> css? Will my program know to use <!--[if IE 8]> for only IE 8 and <!--[if IE 7]> for IE 7?


回答1:


It does not mean "If IE 8 or lower".

<!--[if IE 8]>

Means if it is IE8

<!--[if lt IE 8]>

If it is less than IE 8

<!--[if lte IE 8]>

If it is less than or equal to IE 8




回答2:


If you do as in your example, IE8 will get mystyleIE8.css and IE7 will get mystyleIE7.css.

These are called conditional comments. You could use other syntaxes for other scenarios. In this example:

<!--[if lte IE 7]>
stuff
<![endif]-->

the "stuff" would only apply to all versions of Internet Explorer 7 and lower.

For more, see http://www.quirksmode.org/css/condcom.html, for example.




回答3:


KatieK is correct. If you look inside the comments:

if IE 8

Means "If the browser is IE version 8", which includes only IE8.

if IE 7

Means "If the browser is IE version 7", which includes only IE7.

There's syntax that DOES allow less than. But what you showed isn't it. Contrast with

if lte IE 8

Means "If the browser is less than or equal to IE version 8", which includes IE8, IE7, IE6, and IE5.5.

if lte IE 7

Means "If the browser is less than or equal to IE version 7", which includes IE7, IE6, and IE5.5.




回答4:


You can try the following CSS Hacks. Interesting stuff.



来源:https://stackoverflow.com/questions/5835485/css-for-ie-8-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!