0

I have created a style for media= print like this:

#content .inner h2 {
background:Red;
border-bottom:solid 1px #dfdfdf;
color:#000000;
font-size:20px;
padding-left:10px;
}

But red color is not shown when i print preview. If i set the media=screen and use this stylesheet. then red color is shown. any hint for this?

DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

2 Answers2

4

Depends which browser you are using, but I suspect MSIE?

By default, many browsers will choose not to render the background color for a page when going to print mode (there is usually a setting / option in the print preferences dialog to change this).

Another thing to consider - when you are referencing the style sheet it is possible you either:

  • didn't correctly specify the media type so it isn't loading
  • the browser has buggy behavior and doesn't ever load the style
  • your print style is being overridden by another style

There are lots of tools freely available which can help you to identify the styles being applied to any given element on a page. If you use FireFox, check out the Web Developer extension (also available for Google Chrome on the authors site). If you use MSIE or other browsers, you might be able to get a book marklet script called Aardvark to work (no link because last time I checked the main site was listed as having malware - browse with care).

AJ.
  • 3,062
  • 2
  • 24
  • 32
  • You do a better job of elaborating! – BoltClock Apr 07 '11 at 11:41
  • @BoltClock - thanks. Hit something similar to this question a long time ago; probably worthy of a nice acronym... something like "WYSINWYG" - what you see is _not_ what you get :) – AJ. Apr 07 '11 at 11:46
3

Most browsers simply ignore background and its related properties in print stylesheets. Some of them may have some configuration option that allows printing of backgrounds, but it's a user choice, and most of the time they'll default to not print.

So in short: you can't rely on background styles in print stylesheets.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • just beat me to it - guess I type too much :) – AJ. Apr 07 '11 at 11:38
  • I think it's safe to say 'most browsers'. Note that there has been some recent discussion of this on the [CSS WG mailing list](http://lists.w3.org/Archives/Public/www-style/2011Feb/0626.html). – robertc Apr 07 '11 at 11:41
  • @robertc: Thanks, amended. The link is useful too. – BoltClock Apr 07 '11 at 11:42