为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

呼如林 2023-12-19 20:50:24
我正在尝试使用 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 }结果 :
查看完整描述

1 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

在 css 页面中添加 -webkit-print-color-adjust: exact; 解决了 chrom 中的问题,color-adjust: exact; 解决了 mozilla firefox 中的问题!



查看完整回答
反对 回复 2023-12-19
  • 1 回答
  • 0 关注
  • 74 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信