本文介绍了如何使用分页符打印大型HTML表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印一个大的HTML表,而又不破坏每页末尾的行.我使用了以下代码,但无法正常工作.

I want to print a large HTML table without breaking it's rows at the end of each page. I used following code, but its not working.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style>
@media print
{
  table { page-break-after:auto }
  tr    { page-break-inside:avoid; page-break-after:auto }
  td    { page-break-inside:avoid; page-break-after:auto }
  thead { display:table-header-group }
  tfoot { display:table-footer-group }
}
</style>

<body>
<table border="1">
 <?php
 for($i=0;$i<50;$i++){
 ?>



  <tr>
        <td height="50" width="130">gukgu</td>
        <td height="50" width="180" height="50" width="145">gukgu</td>
        <td height="50" width="130">gukgu</td>
        <td height="50" width="180" height="50" width="145">gukgu</td>
 </tr>
  <?php
  }
   ?>
</table>   
</body>
</html>

有人可以帮忙吗?

推荐答案

您可以尝试使用orphans指定要在页面底部保留的空行数;如果元素的布局与orphans设置冲突,则该元素将被打印在下一页上.浏览器的支持还很低劣.我会在您的示例中将其设置在tr上,如下所示:
tr{orphans:3}

you could try using orphans to specify the number of empty lines to be left at the bottom of a page; if an element's layout conflicts with an orphans setting, the element will be printed on the next page. browser support is pretty shoddy though. i would set it on tr for your example, like this:
tr{orphans:3}

这篇关于如何使用分页符打印大型HTML表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 13:06