In 2003 I wrote an article on how to use CSS to make web pages printable. I figure that it made sense to include it here … the article:
One of the classic problems with how web pages are designed, is that they are horrible to print. Horrible in the sense that page elements (text, images, etc.) don’t line up and unwanted images and navigation links get printed.
I am as guilty as anyone of creating pages like that, but I am aiming to fix it for your websites and mine. While most other web designers will create separate ‘printable’ pages (big waste of time), we will only be making some simple additions to our pages to make them ‘print friendly’.
* People will print your pages typically to be able to read the content, not to see pictures. You need to hide all images from the printer and this is done in the print style sheet. I will explain what the print style sheet is in a moment.
* Navigational elements are not needed in the printed document as well, so all navigational elements should be removed from the printed page.
* Let’s say you designed your pages with a black background with white text. You don’t want peoples printers printing all that black, they won’t be too happy with the price of ink these days! To solve this problem, in our print style sheet we will set the page color to ‘white’ and the text color to ‘black’.
The ‘print style sheet’:
I’ve mentioned the ‘print style sheet’ a few times with no explanation; let’s take care of that now:
CSS today allows you to link to more than one style sheet in your web page.
The simple reason you would want to do this is so that you could have the HTML page ‘change’ its appearance automatically when someone visits your page with a particular type of device. These types of devices can include a typical desktop computer, a PDA (Windows CE device, Palm Pilot, etc.) and a printer among other devices!
It works like this; when you link a style sheet to your HTML page, there is an attribute that you can specify in the CSS link tag that tells the device reading your page if it should use the style sheet specified in the link.
So the wise men and women that came up with the CSS specification, came up with a few ideas for device types that could be specified in the CSS link. For the sake of this short article we are concerned with only two of them:
Here’s a sample pair of CSS links that point to different style sheets, one for the printer to use and the other for a normal PC monitor to use …
You can check out the rest of the tutorial on making web page printable with CSS on Killersites.com.
Thanks for reading,
StefanThis post was written by: Andrea Barnett
This entry was posted on Monday, February 15th, 2010 at 6:54 pm and is filed under CSS Misc, Killer CSS Tips and Tricks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.