Drupal 7 Browser specific css

前端 未结 3 517
灰色年华
灰色年华 2021-01-03 12:18

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

3条回答
  •  礼貌的吻别
    2021-01-03 12:41

    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 !

提交回复
热议问题