[thelist] @media print background-color

RUST Randal RRust at COVANSYS.com
Thu Apr 29 09:39:16 CDT 2004

David Landy said:

> can i get a b/w printer to print shaded backgrounds using 
> css? if so, how? my table rows are coloured on the screen, 
> and it'd be nice if i could get the backgrounds to shade on a 
> printout.

You need two style sheets.

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

Let's say you have <p class="background">.

To hide it when on screen, you need this rule in 'main.css.'

p.background {
    background: #fff; }

And to print it out, you need this rule in 'print.css.'

p.background {
    background: #ccc; }

Note that you absolutely must use the <link> tag to do this. You cannot
use an inline <style> that uses @import. IE 5 will mistakenly apply the
print stylesheet to the page. Al Sparber of http://www.projectseven.com
and I discovered this yesterday.

Randal Rust
Covansys Corp.
Columbus, OH

More information about the thelist mailing list