2

I have a page where I am printing a <h2> with white color.

When I try to print that <h2> in other color like red, green, blue etc. It prints correctly (correct color), but when I add code to print it in white color it changes and prints in black.

.text-container {
  position: relative;
}

.text {
  position: fixed;
  width: 100%;
  bottom: 0;
  background-color: #000000 !important;
  opacity: 0.5;
  -webkit-print-color-adjust: exact;
  color-adjust: exact;
}

h2,
h3 {
  color: #ffffff !important;
  margin: 0.05208in;
  -webkit-print-color-adjust: exact;
  color-adjust: exact;
}
<div class="text-container">
  <div class="text-center text">
    <h2>Som Text</h2>
    <h3>Some more text</h3>
    <h3>Some more text</h3>
  </div>
</div>

This is my code. Even I test text with simple <p> tag it reflects the same issue. It works perfectly on chrome.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Jnanaranjan
  • 1,304
  • 15
  • 31

1 Answers1

3

Also add !important to -webkit-print-color-adjust. This should work in all firefox, put it in @media print like this...

@media print {
  h2, h3 {
    color: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    color-adjust: exact !important;
    }
}

If still you want exact colour, you should check it in the printer, Appearance and Print Background Colors, by default it's off, look at the image, this worked for me, check it in your printer window setting as the below:

enter image description here

Alireza
  • 100,211
  • 27
  • 269
  • 172
  • You have put a "`" mark on your code. I have tried this but it is not working as well. – Jnanaranjan May 17 '17 at 13:19
  • That was extra, did you try @media print wrapper around your code with !important? – Alireza May 17 '17 at 13:20
  • Yes the whole code is within @media print wrapper. The code is working perfectly for chrome. Issue while printing white color only on firefox. – Jnanaranjan May 17 '17 at 13:21
  • OK, I updated the answer, try this please, it worked for me on MAC for firefox – Alireza May 17 '17 at 13:35
  • Yes, It worked. But I wanted to do something which automatically makes the system to print the colors. Thank You – Jnanaranjan May 18 '17 at 10:49
  • I know, but unfortunatelly you can not fully override the default behaviour of the printer using CSS... unfortunatelly these kinds of things can not be fully managed by CSS – Alireza May 18 '17 at 15:00