Keep contents of a div together for printing in IE8

。_饼干妹妹 提交于 2019-12-05 04:52:01

IE8 support for this feature is buggy.

Although Internet Explorer for Windows version 8 supports the value avoid it is a little buggy in places. For example, if applied to a p element, the browser will try to avoid breaking the page inside the element as expected; but if applied to a ul element, the whole list is not set to avoid as the list may span the two pages. That said, the individual list element will try to avoid having a page break inside.

From this example, we can conclude it will try to not break the page inside the p, nor inside the table, but it won't combine both. You can test it by having a really long text in your <p>.

A way to fix this would be to include your title in your table :

  <table style="page-break-inside:avoid;" border="1">
    <tr><th colspan="3">Table title which needs to be kept with the table</th></tr>
    <tr><td>one</td><td>two</td><td>three</td></tr>
    <tr><td>one</td><td>two</td><td>three</td></tr>
    [...]

page-break only works on a paged media context, like @media print:

@media print {
  tr {
    page-break-inside:avoid;
  }
}

Try to use <th> and add title

for example

<table>
    <tr>
        <th>your title</th>
    </tr>
    <tr>
        <td>one</td>
        <td>two</td>
        <td>three</td>
    </tr>
</table>

CSS use @ media

@media print {
    tr th {
    page-break-inside:avoid;
    }
}

Recently i have created print version HTML it works fine! hope it helps you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!