2010-01-12 57 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浏览器上的支持非常广泛。

相关问题