![]() |
|||||||||||||||||||||
CSS Tip:
|
|||||||||||||||||||||
| Page element/ style class | Basic Style Sheet | Print Style Sheet |
body //change background and font colors// |
{ |
margin:0px; |
.logoTable |
padding:0px; |
padding:0px; |
td.menu |
{ |
{display:none;} |
.referrer |
{display:none;} |
{ |
Save this revised style sheet as "PrintStyles.css" and we're ready to link it to the document.
If you've used external style sheets or external JavaScript files before, you're familiar with the LINK element.
Link an external style sheet like this:
<link rel="stylesheet" type="text/css" href="styles.css">
When you add a print style sheet, you have to add the "media" attribute. This tells the browser that the styles contained in that .css file should only be used when the document is printed.
<link rel="stylesheet" type="text/css" href="PrintStyles.css" media="print">
The easiest way to create printable pages is just to add two LINK tags to each page; that's what we just did. One links the basic layout external style sheet and the other contains the printable style sheet. It's a seamless process: your visitor clicks uses the PRINT option in her browser and the printer coughs up the printable version.
To see how this works, view the original file in your browser again. Then select the Print Preview option in your browser. You should see the page using the print style sheet layout.
Here's how it looks in Firefox:

It's easy and everyone is happy, right? Maybe not.
Perhaps your visitor really wanted an exact copy of the page—for whatever reason. She may be confused and frustrated when she can't print one. It's always possible to take a screen shot and then print that, but many inexperienced users don't know how.
So consider adding a "Printable Version" link in a prominent place. That's a standard hyperlink that links to a page that uses only the "print.css" style sheet. Note: don't use the "media" attribute in the LINK tag because you want the visitor to see a preview of what he's about to print.
That would mean that the link on your standard layout page would look something like this:
<a href="calendarPrint.htm" title="Printable version of Zorra's Garden Retreat calendar of events">Printable Version</a>
Then, the calendarPrint.htm page would have only one LINK tag:
<link rel="stylesheet" type="text/css" href="print.css">
This gives your visitor more control, but it's also a lot more trouble if you're coding everything by hand. That's why you may want to consider adding printable version of just a few of your most important or content-rich pages:
If your site has a lot of content that visitors may want to print for later reference, printable pages may be worth the extra effort it takes to create them. There are plenty of good reasons for print-friendly pages:
One disadvantage to you as a webmaster though, is that they're a little more complex, so it's easier to make HTML errors that create browser display problems. Always check your HTML code with NetMechanic's HTML Toolbox after every change. You'll avoid simple errors that can hide content or break your page entirely.
It's also important to check the new pages in as many browsers and browser versions as possible—particularly when you're relying on CSS to style page content. Browsers just don't always display CSS rules like you expect, so use NetMechanic's Browser Photo tool to quickly check for unwelcome surprises.
Browser Photo displays your page in 24 different browsers, browser versions, and operating system combinations. You'll quickly find out if your "printable" page has display problems.
Webmaster Tutorials |
Webmaster
|
Quick SearchSearch our newsletter archives by keyword phrase. |
Volume 7 (2004) Volume 6 (2003) Volume 5 (2002)
|
|