【问题标题】:how to set background image in print page(template) in django如何在 django 的打印页面(模板)中设置背景图像
【发布时间】:2013-06-06 23:01:37
【问题描述】:

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 将背景图像应用到打印页面。但是,如果我按下打印按钮并看到打印预览,则缺少背景图像。我也检查了用纸打印它,图像丢失了。

【问题讨论】:

    标签: html css django django-templates


    【解决方案1】:

    如果您要打印背景图片,请按照以下步骤操作

    1.在 Chrome 和 Safari 网络浏览器中启用后台打印添加

    -webkit-print-color-adjust:exact;
    

    在你的 print.css 文件中,其余的都是一样的

    2.在FireFox中默认"Print Background colours and images"在他们的打印设置中关闭,no CSS will override that.

    如果需要背景图片,用户应手动开启。

    FF开启背景步骤:

    Go to File -->Page setup -->Formats & Options -->Tick Print background(images & colors)
    

    【讨论】:

    【解决方案2】:

    您不能在 css 文件中使用 STATIC_URL。只能在模板中使用。

    【讨论】:

    • 在css中如何设置图片url,我用的是django
    • 只写完整链接:background:url('../images/human.png');
    • 这种方式我也试过了,但没有应用表格的背景图片。
    猜你喜欢
    • 2013-07-08
    • 2017-01-27
    • 2015-02-16
    • 1970-01-01
    • 2017-07-18
    • 2013-04-07
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多