Drupal 7 浏览器特定 css [英] Drupal 7 Browser specific css
本文介绍了Drupal 7 浏览器特定 css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Drupal 7 中拥有特定于浏览器的 CSS.如果浏览器是 chrome ,我想加载 chrome.css .请帮忙
How can i have a browser specific css in Drupal 7 . I would like to load chrome.css if browser is chrome . Please help
推荐答案
你可以在你的 template.php 文件中使用 preprocess_html 主题钩子和 drupal_add_css 函数.
You can do this in your template.php file with a preprocess_html theme hook and drupal_add_css function.
您会在 drupal 7 主题中找到示例,例如在 bartik 中:
You will find example in drupal 7 theme, for example in 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'] :
Edit : since there are no conditional comments for chrome, you can check $_SERVER['HTTP_USER_AGENT'] :
if (isset($_SERVER['HTTP_USER_AGENT'])
&& stripos($_SERVER['HTTP_USER_AGENT'], 'chrome')!==false) {
drupal_add_css( ... );
}
但在此之前,尝试修复您的 CSS 规则!
这篇关于Drupal 7 浏览器特定 css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文