html - 打印页面时显示背景颜色

标签 html css printing

我有从我的网站打印报告的页面,我设置了显示网格结果的表格。

所以,我的问题是,我设置了 th 属性表背景颜色,这个背景在打印之前显示在页面上,但是当打印它时,th 背景不显示。

这是我的 CSS 代码:-

@media print {
.head th {
    background: #CCCCCC;
    background: -webkit-gradient(linear, left top, left bottom, from(#CCCCCC), to(#CCCCCC));
    background: -moz-linear-gradient(top,  #CCCCCC,  #CCCCCC);
    border: 1px solid #000000;
    font-size: 16px;
    text-align: center;
    font-weight:bold;
    padding:10px;
    }
    }
.wrap{
     width: auto; 
     background:#fff;
     word-wrap: break-word;
     margin:30px;
}
th {
    background: #CCCCCC;
    background: -webkit-gradient(linear, left top, left bottom, from(#CCCCCC), to(#CCCCCC));
    background: -moz-linear-gradient(top,  #CCCCCC,  #CCCCCC);
    border: 1px solid #000000;
    font-size: 16px;
    text-align: center;
    font-weight:bold;
    padding:10px;
}

如何在打印此页面时显示第 th 背景。

最佳答案

尝试查看 -webkit-print-color-adjust:exact; 让您的浏览器打印彩色背景...

值(value)观:

经济 正常行为。仅当用户在浏览器的打印设置对话框中明确允许时,才会打印背景颜色和图像。

准确 始终打印应用此规则的元素的背景颜色和图像,用户的打印设置将被覆盖。

希望对你有帮助

关于html - 打印页面时显示背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16256006/

相关文章:

html - 如何在 Kramdown Markdown 中水平居中 HTML 元素?

multithreading - Perl 线程打印不正确

printing - 如何使用 smbclient 以双面模式打印?

html - 图像如何加载到浏览器中?

javascript - 使用 JavaScript 和 CSS 创建悬停和点击

javascript - 如何将单选按钮创建为按钮?

html - 在 firefox 上更改选项卡后 body 的背景图像消失

c - 在c中打印一个二维字符串数组

javascript - (jQuery mobile) 动态网格显示很差

javascript - 使用 jQuery .click 从一些 CSS 类更改为其他 CSS 类而不进行切换?