使用 window.print() 打印时背景颜色消失

我正在尝试使用 window.print(); 在 anglat 中打印页面,一切正常,所有其他 css 都正常工作,唯一的问题是背景颜色没有显示在可打印文档中,我附上了一个 StackBlitz 示例,所以:以前有人遇到过这个问题吗? ,如果是的话解决办法是什么,谢谢。

StackBlitz 示例来自此处


可打印文件 HTML :

<div class="page-container">

<div class="title-container">Invoice Title</div>

<div class="body-container">

  This is what I'm going to print, everything works fine , but the background color never changes , no matter what i add to css file

</div>

</div>

页面的CSS:


.page-container{

  width: 100%;

  background-color : rgb(216, 23, 23);  // as you can see , background not working 

}

.title-container{

  font-size: 24px;

  width: 100%;

  display: flex;

  flex-direction: row;

  justify-content: center;

  padding-bottom: 20px;

  border: 2px blueviolet solid;

  color: rgb(228, 0, 228);

  background-color : rgb(221, 0, 0) !important;// not working also

}

.body-container{

  background : #000; // not working 

}

结果 :

https://img1.sycdn.imooc.com/658191b10001f87005760270.jpg

呼如林
浏览 78回答 1
1回答

狐的传说

在 css 页面中添加&nbsp;-webkit-print-color-adjust: exact;&nbsp;解决了 chrom 中的问题,color-adjust: exact;&nbsp;解决了 mozilla firefox 中的问题!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5