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:-
<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:
-
@media print {
-
h1, h2 {
-
color: Black;
-
}
-
…
-
}







Comments
This is exactly what I was looking for. One example had codebehind and user controls and all kinds of overhead to allow the print functionality. This is simple and standard, I love it.
Thanks!
Excellent solution. Thank you!
Thank you for showing us this trick
Thanks. xcly what i was looking for!
…does this work in all modern browsers btw?
Yeah. @media has been supported by the modern browsers for a while now. Even works in IE6. :)