2013-04-08 86 views
1

我有樣式表文件,並希望禁用IE7和IE8瀏覽器中的一些CSS標籤,如何做到這一點?我不想把這些標籤放在單獨的css文件中,我想保留在一個文件中。從這裏禁用IE7和IE8的CSS樣式

+0

與「禁用CSS標籤」你說話隱藏標記中的一些元素?你能告訴我們一個具體的例子嗎? – fcalderan 2013-04-08 10:18:45

+0

告訴我們的CSS,所以我們可以提供一個例子。 – 2013-04-08 10:19:45

回答

3

我建議採用HTML5樣板文件outlined here by Paul Irish。基本上,這樣設置你的文檔:

<!DOCTYPE html> 
<!--[if lt IE 7]>  <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> 
<!--[if IE 7]>   <html class="no-js lt-ie9 lt-ie8"> <![endif]--> 
<!--[if IE 8]>   <html class="no-js lt-ie9"> <![endif]--> 
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> 

你現在已經有了準確定位某些版本的IE的類。你的CSS看起來就像這樣:

.element { margin-bottom: 20px; } 
.lt-ie8 .element { margin-bottom: 10px; } 

然後你避免CSS黑客,並可以把一切都在一個單一的樣式表。

由於@丹尼爾說,這不是禁用樣式,而是超越它們。如果由於某種原因,你想發送樣式到只有現代瀏覽器和較新的IE,你可以添加另一個類到上面的最後html標籤,並使用它。

+0

覆蓋的CSS樣式是我需要! – Tomas 2013-04-08 14:13:02

1

如果您嘗試有特定的樣式表僅適用於IE它是這樣的:

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

更多關於這家在這裏:How To Create an IE-Only Stylesheet