httpremix.com

About the Author

Jonah Ellison lives in Seattle, Washington and works at a web firm developing websites and custom web applications for the LAMP solution stack. He enjoys optimization, front-end usability, databases, clean code and clever solutions. Contact him or learn more.

 

Topics

Related Articles

Create “Printer-Friendly” Pages with CSS and the @media Type 2008 May 7

Topics: css — by jonah ellison

There may be a time when a visitor wants to print a page from your website. It's worth spending five minutes to create "printer-friendly" pages using CSS. (Tip: navigate to "Print Preview" on your browser to see how this page looks when printed out.) Some of you may already know about the <link rel="stylesheet" type="text/css" href="print.css" media="print" /> directive, however, it's better to place your print CSS within your main CSS file. Instead of having a separate CSS file for printing (which can increase the initial load time since the browser must make an additional HTTP request to the server before rendering the page), place @media print {... } at the bottom of your CSS file. It must be at the bottom to override your previous declarations.

  1. .printContent { visibility:hidden; position:absolute; } /* print only content */
  2.  
  3. @media print {
  4.      /* Page content */
  5.      #page, #colContent { margin:0px; padding:0px; width:inherit; }
  6.      #page { padding:0% 5%; } /* Firefox fix for margin cut-off */
  7.  
  8.      /* Hide these elements */
  9.      #header, #colTopic, #colAbout, #navFooter, .noPrint
  10.      { display:none; }
  11.  
  12.      .pageBreak { page-break-before:always; }
  13.      .printContent { visibility:visible; position:relative; }
  14.      h1 { color:#000; }
  15. }


No Comments »

No comments yet.


Leave a comment

RSS feed for comments on this post - TrackBack URL