Drupal 7浏览器特定的css [英] Drupal 7 Browser specific css

查看:176
本文介绍了Drupal 7浏览器特定的css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Drupal 7中具有浏览器特定的CSS。如果浏览器是chrome,我想加载chrome.css。请帮助

解决方案

您可以在您的template.php文件中使用preprocess_html 主题挂钩和

/ p>

  //为IE 
添加条件样式表drupal_add_css(path_to_theme()。'/css/ie.css',array ('group'=> CSS_THEME,'browsers'=>数组('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规则


How can i have a browser specific css in Drupal 7 . I would like to load chrome.css if browser is chrome . Please help

解决方案

You can do this in your template.php file with a preprocess_html theme hook and drupal_add_css function.

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));

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( ... );
}

But before doing this, try to fix your css rules !

这篇关于Drupal 7浏览器特定的css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆