html - 使用 window.print() 打印时背景颜色消失
问题描述
我正在尝试使用 angulat 打印页面window.print();
,一切正常,所有其他 css 工作正常,唯一的问题是背景颜色未显示在可打印文档中,我附上了 StackBlitz 示例,所以:有以前有人遇到过这个问题吗?,如果是,有什么解决办法,谢谢。
注意:我在stackoverflow和其他论坛上做了很多研究,没有人谈论这个问题。
可打印文件 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
}
结果 :
解决方案
添加-webkit-print-color-adjust: exact;
到 css 页面解决了 chrom 中的问题,并color-adjust: exact;
解决了 mozilla firefox 中的问题!
推荐阅读
- php - 术语“INI 文件”是指在“php.ini”或“.user.ini-style INI 文件”之后解析的配置文件,如“.htaccess”文件?
- android - 如何通过 rxjava2 包装监听器并处理线程切换?
- php - 如何从已保存在数据库中的 pdf 内容生成 pdf
- php - 用php中json字符串中的单引号替换双引号
- python - ValueError: 找到具有 0 个特征的数组 (shape=(546, 0)) 而至少需要 1 个
- javascript - 在从反应应用程序的下拉列表中选择选项时按字母顺序对对象数组进行排序
- javascript - 如何在同一行中对齐图例标签中的三个元素?
- performance - 如果我们已经在 FeedOption 中设置了分区键,那么查询是否应该包含分区键?
- laravel-5.4 - Yajra DataTable 搜索栏无法正常工作
- julia - 创建以符号为键的函数字典