how to specify different css for ie

时光毁灭记忆、已成空白 提交于 2019-12-08 06:40:24

问题


I need to include different .css files for IE anf all other browsers.

I tried the following but it doesn't work.

<!--[if !IE]><!-->
<link type="text/css" rel="stylesheet" href="css/my_style.css">
<!--<![end if]-->
<!--[if IE]><!-->
<link type="text/css" rel="stylesheet" href="css/my_style_IE.css">
<!--<![end if]-->

回答1:


You can give css path this way for IE condition.

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

You can get better help from below link.

http://www.quirksmode.org/css/condcom.html

Enajoy...!! :)




回答2:


Here is a good page that gives a great list of examples for what you are looking for:

ie only stylesheet

Target ALL VERSIONS of IE

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

Target everything EXCEPT IE

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

Target IE 7 ONLY

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

Target IE 6 ONLY

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

Target IE 6 and LOWER

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

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

Target IE 7 and LOWER

<!--[if lt IE 8]>
    <link rel="stylesheet" type="text/css" href="ie7-and-down.css" />
<![endif]-->

<!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="ie7-and-down.css" />
<![endif]-->

Target IE 8 and LOWER

<!--[if lt IE 9]>
    <link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->

<!--[if lte IE 8]>
    <link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->

Target IE 7 and HIGHER

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

<!--[if gte IE 7]>
    <link rel="stylesheet" type="text/css" href="ie7-and-up.css" />
<![endif]-->

Target IE 8 and HIGHER

<!--[if gt IE 7]>
    <link rel="stylesheet" type="text/css" href="ie8-and-up.css" />
<![endif]-->

<!--[if gte IE 8]>
    <link rel="stylesheet" type="text/css" href="ie8-and-up.css" />
<![endif]-->



回答3:


Check this About conditional comments

Example:

<!--[if IE]>
<p>Welcome to Internet Explorer.</p>
<![endif]-->



回答4:


I think you missed /> at the end of your link elements

<link type="text/css" rel="stylesheet" href="css/my_style.css" />



回答5:


What happens when try it like this?

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

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



回答6:


You've got several errors defining the conditional comments:

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

This should do the trick.



来源:https://stackoverflow.com/questions/16279772/how-to-specify-different-css-for-ie

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