Adding stylesheets for alternate media

If you want to add media-specific stylesheets (e.g. any of those listed at http://www.w3.org/TR/REC-CSS2/media.html), use the following snippet in your page.tpl.php file to properly add them using Drupal theme functions.

<head>
  <title><?php print $head_title ?></title>

  <?php print $head ?>

  <?php
   
print theme('stylesheet_import', base_path() . path_to_theme() . '/css/screen.css', 'screen'); // FOR COMPUTER SCREENS
   
print theme('stylesheet_import', base_path() . path_to_theme() . '/css/print.css', 'print'); // FOR PRINTING
   
print theme('stylesheet_import', base_path() . path_to_theme() . '/css/handheld.css', 'handheld'); // FOR HANDHELD DEVICES
 
?>

 
  <?php print $styles ?>
 
</head>

An alternative

jmarkantes - September 7, 2007 - 20:19

If you have only a few lines for an alternative media style sheet, you can add them in your current theme's style sheet and specify the media with the @media rule.

For example, just a short and quick change that helps a lot is to not show the header and sidebars. We have this in our regular theme's style:

@media print{
#header, #sidebar-left, #sidebar-right{display:none;
}
}

Very handy for short changes without having to get into adding more style sheets with the drupal_add_css or theme_add_style stuff.

Jason

 
 

Drupal is a registered trademark of Dries Buytaert.