我想知道是否有任何東西像webkit的條件註釋那樣工作。是否有任何等同於Chrome和Safari瀏覽器的IE條件註釋?
我想改變寬度。
例如,
<!--[if IE]>
<link href="css/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
預先感謝。
我想知道是否有任何東西像webkit的條件註釋那樣工作。是否有任何等同於Chrome和Safari瀏覽器的IE條件註釋?
我想改變寬度。
例如,
<!--[if IE]>
<link href="css/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
預先感謝。
不,沒有。
您可以通過在JS中執行瀏覽器檢測並動態添加腳本/樣式來破解它。或者,如果您只關心爲不同的瀏覽器使用不同的CSS,則可以使用CSS黑客。有可能與您需要的瀏覽器一起工作的CSS黑客。
或者,如果您需要更改的唯一事情是「寬度」(一個CSS定義?)你也許可以做到這一點jQuery的或JavaScript
jQuery的瀏覽器檢測。見: http://docs.jquery.com/Utilities/jQuery.browser
我用這對每一個項目: http://rafael.adm.br/css_browser_selector/
雖然,如果您有做很多Firefox或者Webkit的目標 - 你可能要重新考慮如何你寫你的HTML/CSS。
這對我來說也很好 – evanmcd 2011-04-21 14:14:23
<!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>
基於CSS的解決辦法是答案here。它在Webkit瀏覽器上的支持非常廣泛。
IE的條件註釋是HTML註釋而不是CSS註釋。 – Gumbo 2010-01-12 20:47:21
你說得很對。更新。 – shin 2010-01-12 20:53:42