Drupal 7 Themes – Browser specific CSS

In Drupal 6 you had to target IE specific CSS files by adding lines to your page.tpl.php or use an additional module which allows you to target browsers inside your theme.info file.

In Drupal 7 however, the recommended way is by using the use drupal_add_css() function in your template.php file.

function mytheme_preprocess_html(&$vars) {
  drupal_add_css(path_to_theme() . '/fix-ie.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
}

Leave a comment