Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force browsers to print background images on chrome, firefox

I have a web page that contains some background images and css colors, but when i print the page using ctrl + p its showing page print preview without css and background colors.

I have a div element that has inline style attribute(because the background image of the div will be selected dynamically using for loop in coding) as below

<div class='assessment' style='background-image: url('/static/images/print_%s.png')' >
    <p></p>
    <p></p>
</div>

So i head read something here that we can write print media css to make background images and colors visible by default like

@media print {
.assessment {
   visble:visible;
  }
}

But i don't know how to write this media css with inline css(style='background-image: url('/static/images/print_%s.png')) that i have in my above div

So how to write the media css with the inline css to make the background images visible in the print preview by default when some clicks ctrl+p ?

like image 387
Shiva Krishna Bavandla Avatar asked Mar 13 '14 11:03

Shiva Krishna Bavandla


People also ask

How do I enable print background color and image in Firefox?

First thing to check would be Page Setup. While in Print Preview, click the Page Setup button on the toolbar and make sure you've enabled "Print Background (colors & images)".


1 Answers

This answer will help you. It works for FF and Chrome. First you set !important to your inline css, like so <div class='assessment' style='background-image: url('/static/images/print_%s.png')!important >. Then in your css file:

@media print {
  -webkit-print-color-adjust: exact;
}
like image 70
Ivaylo Petrov Avatar answered Oct 25 '22 03:10

Ivaylo Petrov