我正在试着打印一页。在该页中,我给一个表设置了背景色。 当我在chrome浏览器中查看打印预览时,它没有采用背景色属性…

所以我尝试了这个性质:

-webkit-print-color-adjust: exact; 

但它仍然没有显示颜色。

http://jsfiddle.net/TbrtD/

.vendorListHeading {
  background-color: #1a4567;
  color: white;
  -webkit-print-color-adjust: exact; 
}


<div class="bs-docs-example" id="soTable" style="padding-top: 10px;">
  <table class="table" style="margin-bottom: 0px;">
    <thead>
      <tr class="vendorListHeading" style="">
        <th>Date</th>
        <th>PO Number</th>
        <th>Term</th>
        <th>Tax</th>
        <th>Quote Number</th>
        <th>Status</th>
        <th>Account Mgr</th>
        <th>Shipping Method</th>
        <th>Shipping Account</th>
        <th style="width: 184px;">QA</th>
        <th id="referenceSO">Reference</th>
        <th id="referenceSO" style="width: 146px;">End-User Name</th>
        <th id="referenceSO" style="width: 118px;">End-User's PO</th>
        <th id="referenceSO" style="width: 148px;">Tracking Number</th>
      </tr>
    </thead>
    <tbody>
      <tr class="">
        <td>22</td>
        <td>20130000</td>
        <td>Jim B.</td>
        <td>22</td>
        <td>510 xxx yyyy</td>
        <td>zznn@abc.co</td>
        <td>PDF</td>
        <td>12/23/2012</td>
        <td>Approved</td>
        <td>PDF</td>
        <td id="referenceSO">12/23/2012</td>
        <td id="referenceSO">Approved</td>
      </tr>
    </tbody>
  </table>
</div>

当前回答

CSS属性是所有你需要它为我工作…在Chrome预览时,你可以选择看到它的BW和颜色(颜色:选项-颜色或黑白),所以如果你没有这个选项,那么我建议抓住这个Chrome扩展,让你的生活更容易:

https://chrome.google.com/webstore/detail/print-background-colors/gjecpgdgnlanljjdacjdeadjkocnnamk?hl=en

你在小提琴上添加的网站需要这个在你的媒体打印css(你有它只需要添加它…

媒体打印CSS在body:

@media print {
body {-webkit-print-color-adjust: exact;}
}

更新 你的问题是bootstrap。css。它有一个媒体打印CSS以及你做....你去掉它,就会得到颜色....你需要要么做你自己的,要么坚持用bootstrap打印css。

当我点击打印时,我看到颜色.... http://jsfiddle.net/rajkumart08/TbrtD/1/embedded/result/

其他回答

我只需要在background-color标签上添加!important属性,以便它显示出来,不需要webkit部分:

Background-color: #f5f5f5 !

如果你正在使用bootstrap或任何其他第三方CSS,确保你只在它上面指定媒体屏幕,这样你就可以在你自己的CSS文件中控制打印媒体类型:

<link rel=“stylesheet” media=“screen” href=“”>

CSS属性是所有你需要它为我工作…在Chrome预览时,你可以选择看到它的BW和颜色(颜色:选项-颜色或黑白),所以如果你没有这个选项,那么我建议抓住这个Chrome扩展,让你的生活更容易:

https://chrome.google.com/webstore/detail/print-background-colors/gjecpgdgnlanljjdacjdeadjkocnnamk?hl=en

你在小提琴上添加的网站需要这个在你的媒体打印css(你有它只需要添加它…

媒体打印CSS在body:

@media print {
body {-webkit-print-color-adjust: exact;}
}

更新 你的问题是bootstrap。css。它有一个媒体打印CSS以及你做....你去掉它,就会得到颜色....你需要要么做你自己的,要么坚持用bootstrap打印css。

当我点击打印时,我看到颜色.... http://jsfiddle.net/rajkumart08/TbrtD/1/embedded/result/

对于那些使用BOOTSTRAP.CSS,这是修复!

我已经尝试了所有的解决方案,但都不管用。直到我发现bootstrap.css有一个超级烦人的@media print,它会重置你所有的颜色,背景色,阴影等等…

@media print{*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}

所以要么从bootstrap。css(或bootstrap。min。css)中删除这个section

或者在你想要打印的页面的css中覆盖这些值

@media print {
  body { 
    -webkit-print-color-adjust: exact; 
  }
  .customClass{
     //customCss + !important;
  }
  //more of your custom css
}

我双重加载我的外部css源文件,并将media="screen"更改为media="print",我的表的所有边界都显示出来了

试试这个:

<link rel="stylesheet" media="print" href="bootstrap.css" />

<link rel="stylesheet" media="screen" href="bootstrap.css" />