不会在IE9的每个页面上打印

时间:2012-06-14 23:15:21

标签: html css printing html-table

我有一个包含在表格中的报告。我使用<thead>作为表头,样式为display: table-header-group;,以便在打印时在每个页面上打印标题。这在大多数浏览器中都可以正常工作,但IE 9除外。

不幸的是,我无法提供实际代码,因为它是包含专有信息的订单。我已经尝试了几种doctypes,但是当打印到打印机时,似乎无法让IE 9在每页上打印表头。有没有人遇到这个问题并知道修复?

HTML

<table id="pt">
    <thead>
        <tr class="header">
            <td colspan="4">
                <h1>egdfgsdfg</h1>
                <h3>sdfgsdfg</h3>
            </td>
            <td colspan="2" class="align-right">
                <h2>sdfgsdfg</h2>
                sdfgsdfgsdfg
            </td>
        </tr>
        <tr class="contacts">
            <td colspan="3">sdfgsdfg</td>
            <td colspan="3">sdfgsdfgs</td>
        </tr>
        <tr class="header-info">                
            <td>asdfadfasdf</td>
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr class="column-headers">               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
    </thead>
    <tbody>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
    </tbody>
</table>

CSS:

#pt thead {
    display: table-header-group;
}

5 个答案:

答案 0 :(得分:1)

尝试通过IE的开发工具使用'兼容性'设置,看看它是否有效。如果实际设置有效,您可能必须使用META标记来强制它。只是为了看看它是某个地方的css还是实际的IE 9。

答案 1 :(得分:0)

尝试自己指定所有CSS属性

<style type="text/css" media="print,screen" >
th {
    font-family:Arial;
    color:black;
    background-color:lightgrey;
}

thead {
    display:table-header-group;
}

tbody {
    display:table-row-group;
}
tfoot { 
     display: table-footer-group; 
}
</style>

<table border="1" cellpadding="2" cellspacing="0">
    <thead>
        <tr>
            <th>ID</th>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
    </thead>
    <tbody>
                <tr>
                <td>#i#</td>
                <td>First Name #i#</td>
                <td>Last Name #i#</td>
                </tr>
    </tbody>
</table>

答案 2 :(得分:0)

“如果一个表包含多个带有'display:table-header-group'的元素,则只将第一个元素呈现为标题;其他元素被视为'display:table-row-group'” - W3 .ORG

因此,我希望您在同一页面上没有多个具有该属性的表。

就像Kelly建议的那样,检查兼容性是否导致问题是个好主意。在文档的head部分中使用它,看看它是否有帮助:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

答案 3 :(得分:0)

如何尝试将<td>内的所有<thead>代码更改为<th>代码?

喜欢那样,看看?

<table id="pt" border="1">
    <thead>
        <tr class="header">
            <th colspan="4">
                <h1>egdfgsdfg</h1>
                <h3>sdfgsdfg</h3>
            </th>
            <th colspan="2" class="align-right">
                <h2>sdfgsdfg</h2>
                sdfgsdfgsdfg
            </th>
        </tr>
        <tr class="contacts">
            <th colspan="3">sdfgsdfg</th>
            <th colspan="3">sdfgsdfgs</th>
        </tr>
        <tr class="header-info">                
            <th>asdfadfasdf</th>
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>
        </tr>
        <tr class="column-headers">               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>               
            <th>asdfadfasdf</th>
        </tr>
    </thead>
    <tbody>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
    </tbody>
</table>

答案 4 :(得分:0)

问题出在那些贴在问题之外的标记或样式,正如Jared Farrish在他的评论中暗示的那样。以下html包含已发布的标记和样式,但主体行重复足够多次以创建两个打印页面。 IE9使用我测试的所有浏览器模式/文档模式组合在打印预览的两个页面上显示标题。

测试了浏览器模式/文档模式:

  • Internet Explorer 9 / Quirks
  • Internet Explorer 9 / Internet Explorer标准
  • Internet Explorer 9兼容模式/怪癖
  • Internet Explorer 9兼容模式/ Internet Explorer标准

IE9打印预览:

IE9 print preview

IE9版本详细信息:

IE9 version details

完整代码:

<html>
<head>
<style>
#pt thead {
    display: table-header-group;
}
</style>
<body>
<table id="pt">
    <thead>
        <tr class="header">
            <td colspan="4">
                <h1>egdfgsdfg</h1>
                <h3>sdfgsdfg</h3>
            </td>
            <td colspan="2" class="align-right">
                <h2>sdfgsdfg</h2>
                sdfgsdfgsdfg
            </td>
        </tr>
        <tr class="contacts">
            <td colspan="3">sdfgsdfg</td>
            <td colspan="3">sdfgsdfgs</td>
        </tr>
        <tr class="header-info">                
            <td>asdfadfasdf</td>
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr class="column-headers">               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
    </thead>
    <tbody>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
        <tr>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>               
            <td>asdfadfasdf</td>
        </tr>
    </tbody>
</table>
</body>
</html>