2013-03-21 85 views
2

我有一个有数百行的长表。要在每个页面上打印表格标题,我使用THEAD {display:table-header-group}对表格进行样式设置。它在Firefox和IE9中按预期工作。但是,当我试图强制分页符如下面的代码所示,它不适用于IE9。使用IE9时,表格标题只会打印表格自然分页的页面。带强制分页符的打印表格

这里是代码片段 -

CSS: 
@media print { 
    thead { display: table-header-group; } 
} 

HTML/PHP: 
    <table> 
     <thead> 
     <tr> 
      <th>Header 1</th> 
       <th>Header 2</th> 
       <th>Header 3</th>   
      </tr> 
     </thead> 
     <tbody> 
      <?php 
      foreach ($items as $item) { 
       echo " <tr> " ; 
        echo "<td>text</td>" ; 
        echo "<td>text</td>" ; 
        echo "<td>text</td>" ; 

        if ($condition) { 
         echo "</tr>" ; 

         echo "<tr style='page-break-after:always;'>" ; 
         echo "</tr>" ; 
        } 
      } 
      ?> 
     </tbody> 
    </table> 

,将会极大地有这方面的帮助。

谢谢。

+0

不需要回声支架,你可以将其删除:) – 2013-03-21 16:22:09

+2

我从另一篇文章引述'在所有父元素上设置float:none会使page-break-before:始终正常工作。'如果这有帮助。按照> http://stackoverflow.com/questions/4884380/css-page-break-not-working-in-all-browsers – 2013-03-21 16:36:03

+0

谢谢!我添加了page-break-before而不是page-break-after,并且在每个父元素上将float设置为none,并且它像一个魅力一样工作!再次感谢。 – imhere 2013-03-22 15:08:16

回答

1

开始用正确的HTML与结束标记

if ($condition) { 
    echo ("</tr>"); 
    echo ("<tr style='page-break-after:always;'>"); 
    echo ("</tr>"); 
} else { 
    echo ("</tr>"); 
} 

如果不帮助尝试

if ($condition) { 
    echo ("</tr>"); 
    echo ("<tr style='page-break-after:always;'>"); 
    echo ("</tr> "); 
    echo (' <tr class="class_only_visible_when_printed"> '); 
    echo (" <th>Header 1</th> "); 
    echo (" <th>Header 2</th> "); 
    echo (" <th>Header 3</th> ");   
    echo (" </tr> "); 
} else { 
    echo ("</tr>"); 
} 
+0

谢谢!我已经尝试了第二种解决方案,但IE仍然会自动打印页面。 – imhere 2013-03-21 16:50:59