打印时将多个html表格分成不同的页面 [英] Divide multiply html tables into different pages when printing

查看:65
本文介绍了打印时将多个html表格分成不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HTML 页面显示如下内容:

I have an HTML page displaying content like below:

<html>
    <table></table>
    <table></table>
    <table></table>
</html>

现在我调用 window.print(),并希望将每个表格打印到不同的页面上.我怎样才能做到这一点?

Now I call window.print(), and want each table printed onto the different pages. How can I make this?

PS:每张桌子可能有不同的高度

PS: Each table may have different height

推荐答案

把每个表格都放在 div 中,并像这样设置样式为 div:

Put every table in div, and set style to div like this:

<div style="page-break-after:always;">

这个样式"告诉浏览器,一旦该 div 完成所有内容,它就应该开始在新页面上打印.我们也可以将相同的规则应用于页面上的所有 div,方法是将以下内容添加到其标题中:

This "styling" tells the browser that as soon as that div finishes everything after it should start printing on a new page. We could just as well apply the same rule to, say, all the divs on a page by adding the following to its header:

div {
page-break-after : always;
}

但是,您更有可能只想在某些元素之后而不是在每个段落之后应用中断.这就是为什么最好将样式单独应用或应用到您可以像 DIV 一样有选择地使用的一组元素.

However, it's is more likely that you will want to apply breaks only after certain elements rather than after every paragraph. That's why it is probably better to apply the style individually or to a set of elements that you can use selectively like the DIV.

阅读这个了解更多信息...

Read this for more info...

这篇关于打印时将多个html表格分成不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆