2013-04-29 41 views
1

我需要爲IE和所有其他瀏覽器包含不同的.css文件。如何爲ie指定不同的css

我試過以下,但它不起作用。

<!--[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]--> 
+0

你應該添加ie的版本,例如!IE6 – Somesh 2013-04-29 13:25:26

+1

請注意,條件註釋不適用於IE10。 – lifetimes 2013-04-29 13:29:24

回答

1

你可以給CSS路徑這樣的IE瀏覽器的條件。

<!--[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]--> 

您可以從下面的鏈接中獲得更好的幫助。

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

Enajoy ...!:)

1

入住這 About conditional comments

例子:

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

也應該包括*除*以外的條件註釋:'不是IE '。 – Sampson 2013-04-29 13:40:41

0

我想你錯過了你的鏈接元素的末尾

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

時嘗試它像會發生什麼/>這個?

<!--[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]--> 
+0

只適用於css/my_style_IE.css – Gayane 2013-04-29 13:46:24

0

您收到幾個錯誤定義的條件註釋:

<!--[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]--> 

這應該做的伎倆。

2

這裏是一個很好頁面給出了一個例子你正在尋找一個偉大的名單:

ie only stylesheet

目標IE所有版本

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

目標一切,除了IE

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

僅針對IE 7

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

目標IE 6 ONLY

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

目標IE 6和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]--> 

目標IE 7和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]--> 

目標IE 8和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]--> 

目標IE 7和更高

<!--[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]--> 

目標IE 8和更高

<!--[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]--> 
+1

請提供代碼和示例。如果該鏈接在未來中斷,您的答案將不會有任何功能。 – Sampson 2013-04-29 13:30:37

+0

添加代碼請參閱上面編輯 – Andrew 2013-04-29 13:33:11

+0

感謝您發佈了一些Chris的代碼,但是您也複製/粘貼了很多不必要的東西。該OP只想知道如何瞄準IE - 不是每個特定版本的IE :) – Sampson 2013-04-29 13:34:30

相關問題