Is it possible to change the background color of an element for printing?

0

Is it possible to change the background of an element in the print style sheet? I have the following code:

<td valign="top" bgcolor="#dddddd" class="cinza" nowrap="">Seu Nome<br>
<div align="right" class="campo">Eu Sou o João</div>
</td>
  • I used bgcolor="#dddddd" , did not work.
  • I used the style <style> :
<style media="print">
.cinza{background-color:#dddddd !important;}
</style>

It did not work either.

  

Is it possible or not to change the background color of an element for printing?

    
asked by anonymous 21.12.2016 / 12:42

2 answers

1

Well, if a user has marked something like "Print background images and colors" (which will depend on the browser) in the options, no CSS will overwrite it. So always take this into account.

But there are some solutions to the various problems that may appear that can help in these various cases:

body {
  -webkit-print-color-adjust: exact;
  background-color:#dddddd  !important;
}
    
21.12.2016 / 13:04
1

You can use Media Query to apply specific styles for printing:

/*CSS para impressão*/
@media print {
  body { -webkit-print-color-adjust: exact;}
   .cinza{ background-color:#dddddd  !important; }
}
    
21.12.2016 / 12:45