CSS:
table.print{
width:123px;
height:298px;
background-position:center;
background:url('{{ STATIC_URL }}images/human.png');
}
HTML:
<table id="human-body" class="print" >
<tr>
<td>some data</td>
</tr>
</table>
上述 HTML 在我的应用程序中用作 django 中的打印模板。我的问题是,我使用上面的 CSS 将背景图像应用到打印页面。但是,如果我按下打印按钮并看到打印预览,背景图像就会丢失。我也检查过用纸打印它,图像丢失了。
最佳答案
如果您要打印背景图片,请按照以下步骤操作
1.要在 Chrome 和 Safari 网络浏览器中启用后台打印,请添加
-webkit-print-color-adjust:exact;
在你的 print.css 文件中,其他都是一样的
2.在 FireFox 中,默认情况下 “Print Background colors and images”
在其打印设置中关闭,没有 CSS 会覆盖它。
如果需要背景图片,用户应手动开启。
在 FF 中打开背景的步骤:
Go to File -->Page setup -->Formats & Options -->Tick Print background(images & colors)
关于html - 如何在 django 的打印页面(模板)中设置背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17038292/