Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div background color not coming when print preview occurs on the page

Tags:

html

css

I have one div in my page:

<div id="div1>

welcome
</div>

I need to set background color for this div using css. so i used background-color css in our page, it works as expected but when I try to print it, it is not showing respective color.

So, I tried to use media code. It works in chrome browser but I don't know whether it will work in all browsers.

@media print {
        #div1 {
            background-color: #E42314 !important;
            -webkit-print-color-adjust: exact; 

        }
    }
    #div1 {
        background-color: #E42314 !important;
    }
like image 928
SivaRajini Avatar asked Sep 04 '25 16:09

SivaRajini


1 Answers

There is this option in browser's print settings where you need to flip the "show background colors and images".

Because this is a browser setting, you won't be able to set this through code.

For example if you are using Chrome, the print options will look like this:

enter image description here

For IE, it will look something like this:

enter image description here

like image 82
Abhitalks Avatar answered Sep 07 '25 07:09

Abhitalks