Printing background-color in Firefox and IE
Asked Answered
M

5

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.

Meltage answered 5/6, 2013 at 18:39 Comment(3)
No one? Please, please help me sharing this post...Meltage
I added a hack here: #765020Crusade
Possible duplicate of CSS @media print issues with background-color;Frieder
I
6
* {
-webkit-print-color-adjust: exact;
printer-colors: exact;
color-adjust: exact;}

Browsers: Chrome, Safari, FireFox

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

Invitation answered 29/8, 2017 at 17:0 Comment(1)
IE - No. Edge (75+) - YesInvitation
A
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.

Aimee answered 9/8, 2013 at 7:54 Comment(2)
Thanks your answer, but I need something that not depends of the user, something in the application to print it automatically, like the hack to Google Chrome.Meltage
unfortunately, this is not possible without user interraction. html printing is really limited.Stank
P
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)

Pasley answered 7/10, 2015 at 8:46 Comment(0)
A
1

For Firefox

color-adjust:exact;

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

Angloamerican answered 14/7, 2017 at 10:38 Comment(0)
M
0

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

Madox answered 30/9, 2014 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.