Drupal 7 浏览器特定的 css

标签 drupal drupal-6 drupal-modules drupal-7 browser-detection

我怎样才能在 Drupal 7 中拥有特定于浏览器的 css。如果浏览器是 chrome,我想加载 chrome.css 。请帮忙

最佳答案

您可以在 template.php 文件中使用 preprocess_html 执行此操作主题 Hook 和drupal_add_css功能。

您会在 drupal 7 主题中找到示例,例如在 bartik 中:

// Add conditional stylesheets for IE
drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));

编辑:由于 chrome 没有条件注释,您可以检查 $_SERVER['HTTP_USER_AGENT']:

if (isset($_SERVER['HTTP_USER_AGENT'])
    && stripos($_SERVER['HTTP_USER_AGENT'], 'chrome')!==false) {
    drupal_add_css( ... );
}

但在这样做之前,尝试修复您的 css 规则!

关于Drupal 7 浏览器特定的 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5883140/

相关文章:

html - CSS通过访问图片URL替换图片

drupal - 尝试更改 Drupal Logo 上的图像 "title"标签

drupal - Drupal 中的模块开发教程

php - 需要Drupal多个自定义字段,如果字段为空则通过验证

Drupal 7 : Contact Form Not Visible, 尽管有权限

复杂关系的 Drupal 最佳实践

drupal - 如何覆盖首页节点tpl-drupal

php - 在 DRUPAL 6 中如何使节点链接直接指向其文件内容?

Drupal:我需要在 block 中显示用户名

ajax - 用于非 JSON 输出的 drupal_json 的任何替代方案