如何使用CSS为各种浏览器覆盖打印首选项?

我有以下CSS:

   @@media only print {
            @@page {
                size: A4 landscape !important;
                margin-top: 0mm !important;
                margin-bottom: 0mm !important;
            }
                #tblPrint tbody tr:nth-child(even) {
                    background-color: #ededed !important;
                }
            * {
                -webkit-print-color-adjust: exact !important;
            }
}

问题如下:

  1. @@ page属性不会在所有浏览器上生效,并且默认浏览​​器的打印首选项会生效,即(Chrome:A4 / Landscape),(Edge:A4 / Portrait),(IE: A4 / Portrait),即使我将size属性翻转为size:A3 portrait!important;相同的默认浏览器的打印首选项将继续生效。

  2. 当我使用“ -webkit-print-color-adjust”时,即使关闭浏览器的打印首选项中的“背景图形”功能,background-color属性也会在Chrome上生效,但是,除非我从浏览器的打印首选项中启用“打印背景色和图像”功能,否则IE不会生效,因为边缘浏览器无法使背景色CSS属性生效。

我需要的解决方案是强制由CSS指定的属性覆盖浏览器的“打印”首选项,而无需用户指定纸张尺寸,方向并检查“背景图形/打印背景色和图像”从浏览器的“所有浏览器的打印首选项”中获取帮助,

xhy_will 回答:如何使用CSS为各种浏览器覆盖打印首选项?

添加样式表的底部

css

@media print { 
    body{ background-color:#000;}
} 
本文链接:https://www.f2er.com/3153858.html

大家都在问