HTML Code:
<link rel="stylesheet" type="text/css" href="layout.css">
<link rel="stylesheet" type="text/css" href="print.css" media="print">
<h1>Latest news</h1>
<p>
The dog ate the bird
<a href="somePage.html">Read all about it!</a>
</p>
Then you use 2 different css files. layout.css will have css for both versions (add media="print" if you only want this css for screens). And print.css will be used additionally when you print.
Content of style.css:
Code:
h1 { font-size:20px; }
p { background-color:red; }
Now, when you print this, you will not want to print the link and also change the background-color of the p element
Content of print.css
Code:
p { background-color:transparent; }
a { display:none; }
This solution does not use JavaScript and does also not pollute the HTML.
Bookmarks