Home  >  Article  >  Web Front-end  >  CSS styles you need to pay attention to when printing on the web

CSS styles you need to pay attention to when printing on the web

一个新手
一个新手Original
2017-09-14 11:11:091966browse

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,
CSS styles you need to pay attention to when printing on the web

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:
CSS styles you need to pay attention to when printing on the web

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn