21

I am with some problems to print background-color in Firefox and IE. For Google Chrome I found the follow hack and it works well, but for Firefox and IE I can't find anything.

//Hack for Google Chrome
-webkit-print-color-adjust:exact;

I am glad if someone can help me with this.

Kara
  • 6,115
  • 16
  • 50
  • 57
Wellington Zanelli
  • 1,894
  • 3
  • 18
  • 43
  • 1
    No one? Please, please help me sharing this post... – Wellington Zanelli Jun 06 '13 at 17:04
  • 1
    I added a hack here: http://stackoverflow.com/questions/764520/how-do-i-make-firefox-print-a-background-color-style/22632508#22632508 – timing Mar 25 '14 at 11:00
  • Possible duplicate of [CSS @media print issues with background-color;](http://stackoverflow.com/questions/3893986/css-media-print-issues-with-background-color) – f_puras Feb 11 '16 at 10:19

5 Answers5

5

For Firefox on the Print dialog there is an Advanced or Show Details button, if you click that , under Appearance there are two checkboxes. One for Print Background Colors and Print Background Images.

EGHM
  • 2,144
  • 23
  • 37
5
* {
-webkit-print-color-adjust: exact;
printer-colors: exact;
color-adjust: exact;}

Browsers: Chrome, Safari, FireFox

More: https://wiki.csswg.org/ideas/print-backgrounds

Pavel Levin
  • 646
  • 8
  • 7
1

If you are OK with having your element being a fixed height/width, you can set its size, put a 1px coloured image into it (of whatever colour you want the background to be) and make it fill the space. Then you can absolutely position your content on top.

<div style="position: relative; width: 100px; height: 100px;">
    <img src="/images/blue.png" style="width: 100px; height: 100px;">
    <div style="position: absolute; top: 0px; left: 0px;">
        Hello world
    </div>
</div>

Or you could do the same thing with a border instead of an image:

<div style="position: relative; width: 100px; height: 100px;">
    <div style="width: 0; height: 0; border: 50px solid black;">
    <div style="position: absolute; top: 0px; left: 0px;">
        Hello world
    </div>
</div>

(Original idea from here: https://defuse.ca/force-print-background.htm)

voidstate
  • 7,937
  • 4
  • 40
  • 52
1

For Firefox

color-adjust:exact;

will work same as -webkit-print-color-adjust:exact;

Floern
  • 33,559
  • 24
  • 104
  • 119
0

Seems impossible, as Spark says, but you can sometime use wide borders as workaround (e.g. div with 0 height and 100px border).

TheZver
  • 1,502
  • 2
  • 14
  • 19