Using print stylesheets with ASP.NET themes

I found a great tip today on a blog called graphical wonder for creating print stylesheets if you’re using Themes in ASP.NET 2.0.

The problem is that all CSS files in the themes directory are automatically included in the of the document as tags. If one of these files is a print stylesheet you don’t get the opportunity to tell the ASP.NET that the media attribute for the file should be print:

  1. <link rel="stylesheet" href="print.css" media="print"/>

It turns out there’s a way to actually embed this information into the document itself. You just need to surround the declarations in your print stylesheet with an @media print declaration like this:

  1. @media print {
  2.   h1, h2 {
  3.   color: Black;
  4.   }
  5.  …
  6. }

Posted on 16 Oct 06 by Helen Emerson (last updated on 16 Oct 06).
Filed under ASP.NET