This is the old MovableType blog. To enter the new blog visit the home page.

September 17, 2003

E-commerce > Printer Stylesheets

I'm still tweaking the blog after switching from Blogger Pro to Movable Type. The latest tweak is to my print stylesheet.

My main page has a list of links on the right-hand side. Anyone printing that page probably doesn't want those links, so I decided to make the sidebar non-printing. This is a quick explanation of how to suppress printing for part of a page.

Most blogging software includes a template with a default stylesheet, either as part of the document header, or as a separate document. Part of the flexibility of Cascading Style Sheets (CSS) is that you can define different stylesheets for different output devices: screen, printer, audio reader, etc.

The first step is to include a line in the document header pointing web browsing software to the print stylesheet (the trailing slash is to make that line XHTML compliant; omit it if you're still validating to HTML 4.01 or earlier):

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

Next, enclose the area you don't want to print in a div tag for a new class called "noprint":

<div class="noprint">stuff you don't want to print</div>

Finally, create a file called print.css on the web server and define a noprint class:

.noprint { display : none; }

That's all you need to designate part of a page non-printing.

Because my new page design has light text on a black ground it could drain an ink cartridge in a hurry. To keep that from happening, I reversed the color scheme for the print.css file (the * matches all elements and classes):

* { color:black; background:white; }

That makes the text print correctly, but I still have some background areas that print in black. Know how to fix it? Post in comments.

Posted by lesjones



Comments

I'm guessing, but you could try

{ color:white; background:white; text:black}

Good post, BTW.

Posted by: Mike Spenis at March 09, 2004

Have you seen this before? It's a number guessing game: http://www.amblesideprimary.com/ambleweb/mentalmaths/guessthenumber.html. I guessed 28836, and it got it right! Pretty neat.

Posted by: Merideth Carleton at January 20, 2006

Comments on the old blog are closed.


Terms of Use