Reputation: 7375
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;
}
Upvotes: 4
Views: 11090
Reputation: 11284
You just need to add the !important
attribute onto the the background-color tag in order for it to show up, you do not need the web-kit tag or even need it wrapped in the @print.
background-color: #f5f5f5 !important;
Upvotes: 4
Reputation: 28387
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:
For IE, it will look something like this:
Upvotes: 6