html - 从 Chrome 打印时仅在 tbody 之间分页

标签 html css printing html-table page-break

我有一个 <table>连续行在概念上相关且需要保持在一起的数据。我将每对行分组在 <tbody> 中标签。当需要打印表格时,我想确保分页符只发生在 <tbody> 之间。标签。

我尝试了 page-break-inside: avoid 的一些变体和 page-break-after: auto , 但似乎无法让它在 Chrome 42 中工作(见下面的截图)

Conceptual group of rows split across two pages... what I don't want

但是,它似乎确实在 Firefox 40 和 IE 11 中按预期工作。看起来像 page-break-*可能只适用于 block 级元素。在 html/css 中有没有好的方法来实现这一点?

示例代码:

<!doctype html>
<html>
<head>
    <style>
        table {
            width: 70%;
            border-collapse: collapse;
        }
        thead {
            display: table-header-group;
            text-align: left;
            border-bottom: 2px solid #000;
        }
        tbody {
            page-break-inside: avoid;
            border-bottom: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>Project #</th>
                <th>Owner</th>
                <th>% Complete</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>HR-123</td>
                <td>Arther Dent</td>
                <td>42%</td>
            </tr>
            <tr>
                <td colspan='3'>Description: Find travel guide to get me back to earth.</td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <td>RD-123</td>
                <td>Frodo Baggins</td>
                <td>9%</td>
            </tr>
            <tr>
                <td colspan='3'>Description: Find a better way to get the ring to Mordor.</td>
            </tr>
        </tbody>
        <!-- repeat tbody sections as necessary to get onto the second page -->
    </table>
</body>
</html>

这是一个 JSFiddle这会让您对我要完成的工作有一些了解。

编辑: 我考虑不使用表格但没有这样做,因为 (i) 我希望我的列对齐,并且 (ii) 我真的不想硬编码列宽以确保它们都是一样的。

最佳答案

尝试将其全部包装在一个 使特定的 block 元素(http://learnlayout.com/inline-block.html) 然后使用分页符-*

关于html - 从 Chrome 打印时仅在 tbody 之间分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33309192/

相关文章:

jquery - 使用 anchor 创建平滑滚动

javascript - 尝试让 jquery-ui 选项卡在传单 map 内的 div 上工作时出错

javascript - 简化并重写我重复的代码

java - 在java中将字体的字符宽度设置为统一

cocoa - 不使用页面设置进行打印 - 对纸张尺寸和方向的变化有何 react ?

java - 如何打印使用 iText 创建的 PDF?

java - 在Android项目中使用HTML解析器

javascript - 在 bootstrap 中垂直定位 .tooltip-inner

javascript - 在运行时在 Angular 中更改应用程序主题

css - Wordpress ACF Repeater 背景图片只加载最后一张图片