Custom CSS for Printer Output

Mon, 10/13/2008 - 12:08

You might not think of it while you are plowing through your css, painstakingly making sure everything is pixel perfect, but when you go to print, through your tears, it will certainly cross your mind. Things look differently when displayed on paper, then they do on screen. So, how can I keep my site from looking like a cascading nightmare when printed? Thankfully the solution is simple. Use CSS!

Firstly create a new stylesheet, let's call it "print.css". You will need make sure that this stylesheet is being linked to, if the page is being viewed as print. This requires a call similar to <link rel="stylesheet" type="text/css" href="path/to/print.css" media="print" /> There are 10 media types defined in CSS2. The "all" media type is certainly the most common and is called by default when linking. In our case we are obviously using "print". From here things should be pretty familiar, It's just CSS. My print.css file tends to have a lot of display: none; calls getting rid of tabs, menus, navigation, etc.. as the idea is to override your existing styles to output something that is legible on paper. It's most certainly worth a look.

ALA

Mon, 10/13/2008 - 12:32
Posted by: rho
As usual here is a great article on things to consider when styling for print, from the folks at A List Apart.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.