2010-01-12 54 views
5

我想知道是否有任何東西像webkit的條件註釋那樣工作。是否有任何等同於Chrome和Safari瀏覽器的IE條件註釋?

我想改變寬度。

例如,

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

預先感謝。

+2

IE的條件註釋是HTML註釋而不是CSS註釋。 – Gumbo 2010-01-12 20:47:21

+0

你說得很對。更新。 – shin 2010-01-12 20:53:42

回答

8

不,沒有。

您可以通過在JS中執行瀏覽器檢測並動態添加腳本/樣式來破解它。或者,如果您只關心爲不同的瀏覽器使用不同的CSS,則可以使用CSS黑客。有可能與您需要的瀏覽器一起工作的CSS黑客。

或者,如果您需要更改的唯一事情是「寬度」(一個CSS定義?)你也許可以做到這一點jQuery的或JavaScript

jQuery的瀏覽器檢測。見: http://docs.jquery.com/Utilities/jQuery.browser

+0

jQuery能檢測瀏覽器嗎? – shin 2010-01-12 21:03:09

+1

是的。試試$ .browser.msie == true。 $ .browser.mozilla == true等。檢查$ .brower對象或閱讀文檔 – mkoryak 2010-01-12 21:12:43

+0

閱讀您的回覆後,我發現它並且工作正常。謝謝。 http://www.tvidesign.co.uk/blog/CSS-Browser-detection-using-jQuery-instead-of-hacks.aspx – shin 2010-01-12 21:14:26

1
<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="UTF-8"> 
<title>Browsser Detection</title> 

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

<?php 

$msie  = strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? true : false; 
$firefox = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') ? true : false; 
$safari  = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari') ? true : false; 
$chrome  = strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome') ? true : false; 

if ($msie) { 
echo ' 
<!--[if IE 7]> 
<link rel="stylesheet" href="ie7.css" type="text/css"> 
<![endif]--> 
<!--[if IE 8]> 
<link rel="stylesheet" href="ie8.css" type="text/css"> 
<![endif]--> 
'; 
} 
if ($safari) { 
echo '<link rel="stylesheet" href="safari.css" type="text/css">'; 
} 

?> 

</head> 
<body> 

    <br> 
    <?php 
    if ($firefox) { //Firefox? 
    echo 'you are using Firefox!'; 
    } 

    if ($safari || $chrome) { // Safari? 
    echo 'you are using a webkit powered browser'; 
    } 

    if (!$msie) { // Not IE? 
    echo '<br>you are not using Internet Explorer<br>'; 
    } 
    if ($msie) { // IE? 
    echo '<br>you are using Internet Explorer<br>'; 
    } 
    ?> 

    <br> 

</body> 
</html> 

Chrome conditional comments

0

基於CSS的解決辦法是答案here。它在Webkit瀏覽器上的支持非常廣泛。

相關問題