HTML and CSS Reference
In-Depth Information
Resetting Layout
One of the first things you should consider with a print layout is resetting any layout mecha-
nisms you've used for the screen view. This involves removing floats, absolute positioning,
padding, and margins. You may want to go through each element and create a print alterna-
tive for each, but that may take time. We suggest using the old “sledgehammer-to-crack-a-nut”
approach: apply several styles to several different elements in one go, and then deal with the
Our travel web site is a good example that we can now prep for print. First things first; let's
link to the necessary CSS files:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<title> - Getting you there since 1972</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="basic.css" rel="stylesheet" type="text/css" />
<!-- which imports the advanced.css file -->
<link href="print.css" rel="stylesheet" type="text/css" media="print" />
Here's the first part of the print CSS for this site. As you can see, we list all the elements
that have been manipulated in one way or another and then reset the CSS back to basics:
body, div, img, h1, h2, h3, ul, ol, li, a, form {
This won't fix all the problems for the print view, mainly because of specificity reasons
(remember reading about that as far back as Chapter 3?). Some of the rules in the main style
sheet have a higher specificity and so, despite our redefinitions in the print CSS, the generic
styles previously declared are more specific. So, we'll need to add some selectors to target
those elements and they must have the same (or greater) specificity (see the additions in
body, div, img, h1, h2, h3, ul, ol, li, a, form,
body#cols3 #content-wrapper {
Search WWH ::

Custom Search