【发布时间】:2010-11-20 12:08:44
【问题描述】:
Chrome 是否有条件 cmets 之类的东西?
与 Firefox 相比,我有一个在 Chrome 中呈现不同的页面。
谢谢
【问题讨论】:
-
如果您可以指定您的问题,那么它可能会更有帮助。
标签: css firefox google-chrome
Chrome 是否有条件 cmets 之类的东西?
与 Firefox 相比,我有一个在 Chrome 中呈现不同的页面。
谢谢
【问题讨论】:
标签: css firefox google-chrome
您可以在您的 CSS 中使用它来定位基于 WebKit 的浏览器
@media screen and (-webkit-min-device-pixel-ratio:0) {
Body {}
}
也许这会有所帮助?
【讨论】:
-webkit-min-device-pixel-ratio(为零或其他),因此条件的第二部分失败。
<!--[if IE 8]><div id="bodyContainer" class="IE8"><![endif]-->
<!--[if !IE]>--><div id="bodyContainer" class="W3C"><!--<![endif]-->
<script type="text/javascript">
if (navigator.userAgent.toLowerCase().match('chrome') && document.getElementById('bodyContainer'))
document.getElementById('bodyContainer').className = document.getElementById('bodyContainer').className + " chrome";
</script>
然后您使用 CSS 专门针对 Chrome 调整样式。
【讨论】:
document.getElementById('bodyContainer').className += " chrome";
据我所知,只有 Internet Explorer 4-8 支持 HTML conditional comments 和 Javascript conditional compilation directives。
【讨论】:
<!--[if !IE]>-->
这不仅仅是一个 Chrome 条件注释 - 这会影响所有不是 IE 的浏览器... 火狐,野生动物园等 如果使用 PHP - 试试这个:
<!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>
【讨论】:
条件操作将起作用,因为其他浏览器会将 If IE8 块解析为 HTML 注释,而不是 !IE 块,因为它的内部包含在 --> 和
因此,对于所有非 IE 浏览器,body 类确实等于 W3C。
不过,这都是顺便说一句,因为不需要 IE 注释块来将浏览器专门识别为 chrome - JS 块本身会做到这一点,前提是用户当然打开了 JS。
【讨论】: