Using CSS for better printing of webpages
Using CSS for better printing of webpages
Aug 30, 2008
How to use CSS to create printable webpages
Classroom: Cascading Style Sheets





Printing webpages

As you have probaly already experienced, printing webpages can yield some interesting results. Even if you change the page setup to landscape the pages can still be ugly and unsuitable for print.

So how can we control the way a web page is displayed in print?

It is all about media

  1. <link href="stylesheet.css" rel="stylesheet"
  2. type="text/css" media="all" />
  3. <link href="stylesheet_print.css" rel="stylesheet"
  4. type="text/css" media="print" />

So as you can see above the second linked style sheet has media type set to 'print'. This means you can add styles to make the your page more pinter friendly. ( Keep in mind though that because the linked stylesheet above is set to media 'all', the second 'print 'sheet will need to override these styles )

What makes a page printer friendly?

To me making ia webpage readable is the objective. So perhaps things like making the text black with serif font wih a suitable size. Also the text paragraph should fit with in a potrait page.

  1. div#content {
  2. font-family: "Times New Roman", Times, serif;
  3. font-size: 12px;
  4. color: #000000;
  5. width: 500px;
  6. }

What else? Well some parts of the webpage are a waste on paper, like menus and videos. So you can remove these elements with a display none.

  1. div#videoad {
  2. display: none;
  3. }

Perhaps also change any background colors to white so the next person who visits your website doesn't clean out a whole cartridge of ink printing your webpage.

Also can be worth removing the underline of your links to blend more with the body text.

  1. a {
  2. text-decoration: none;
  3. }

So there are a few things you can do just by adding in that extra style sheet for print.


Comments

Would you like to comment?

Sign up for a free account, or sign in (if you're already a member).

Teacher

thumb
Simon Taylor
Lessons: 16
Friends: 5
RSS