Today I wrote a function that prints on the front end, and encountered a very pitiful problem. The set background color did not work when printing:
The css style that did not work:
.p_class2_1{ color:white; float:left; background: #808080!important; width:80%; } .p_class3_1{ color:white; float:left; background: #808080!important; width:100%; } .p_class5_1{ color:white; background: #808080!important; width:100%; }
Result Nothing worked,
was later solved through various methods:
The following is the solution code:
.p_class2_1{ color:white; float:left; background: #808080!important; filter:progid:DXImageTransform.Microsoft.gradient(startColorStr='#808080',EndColorStr='#808080'); width:80%; } .p_class3_1{ color:white; float:left; background: #808080!important; filter:progid:DXImageTransform.Microsoft.gradient(startColorStr='#808080',EndColorStr='#808080'); width:100%;} .p_class5_1{ color:white; background: #808080!important; filter:progid:DXImageTransform.Microsoft.gradient(startColorStr='#808080',EndColorStr='#808080'); width:100%;} @media print { .p_class2_1 {-webkit-print-color-adjust: exact;} .p_class3_1 {-webkit-print-color-adjust: exact;} .p_class5_1 {-webkit-print-color-adjust: exact;} }
The results are as follows:
I found the background color that was not displayed before, but it is now displayed!
The most important code is@media print { <br>
.p_class2_1 {-webkit-print-color-adjust: exact;} <br>
.p_class3_1 {-webkit-print-color-adjust: exact;} <br>
.p_class5_1 {-webkit-print-color-adjust: exact;} <br>
}
@media print is to display the background color when printing. It is not displayed by default!
The above is the detailed content of CSS styles you need to pay attention to when printing on the web. For more information, please follow other related articles on the PHP Chinese website!