如何在分页媒体输出的连续页面上设置表格样式?

发布于 2024-09-10 04:39:39 字数 993 浏览 1 评论 0原文

我有一个像这样的 html 表:

<div class="report">
    <table>
        <thead>...</thead>
        <tfoot>...</tfoot>
        <tbody>
            <tr class="row-to-style">...</tr>
        </tbody>
        <tbody>...</tbody>
    </table>
</div>

请注意,上面的所有 tbody 的结构都相同。我想将第一个 tr.row-to-style 行的样式设置为与其他行不同。每个 tbody 都会有一个 tr.row-to-style 但我只想影响页面上的第一个这样的行。输出是分页媒体,特别是 PrinceXML 从 xhtml 源文件生成的 pdf 文件。这意味着我们可以使用高级的css选择器,不需要跨浏览器兼容性,并且不能使用javascript。

在输出的第一页上设置目标行的样式非常容易。我可以使用:

table tfoot + tbody tr.row-to-style {...}

另外,如果我知道一个页面可以容纳多少个 tbody,我可以这样做:

table tbody:nth-of-type(4n+1) tr.row-to-style {...}

但是如果我不知道一个页面可以容纳多少个 tbody,我如何才能定位第一个?

实际上,在输出时,每页都会重复 thead 和 tfoot 部分。这些表是专门为了利用这一点而设计的。我们允许在 tbody 之后进行分页。输出可能包含几页。

因此,输出在每个页面上都有一个伪标题和伪tfoot。但我看不出有什么方法可以使用它来标记页面上的第一个 tbody。有什么想法吗?谢谢...

I have an html table like this:

<div class="report">
    <table>
        <thead>...</thead>
        <tfoot>...</tfoot>
        <tbody>
            <tr class="row-to-style">...</tr>
        </tbody>
        <tbody>...</tbody>
    </table>
</div>

Note that all tbody's above are identically structured. I want to style the very first tr.row-to-style row differently from the others. Each tbody will have a tr.row-to-style but I want to only affect the first such row on a page. The output is paged media, specifically PrinceXML produced pdf files from xhtml source files. This means we can use advanced css selectors, cross-browser compatibility is not required, and javascript cannot be used.

It's easy enough to style the target row on the first page of output. I can use:

table tfoot + tbody tr.row-to-style {...}

Also, if I know how many tbody's will fit on a page, I can do something like:

table tbody:nth-of-type(4n+1) tr.row-to-style {...}

But if I don't know the number of tbody's that will fit on a page, how can I target the first one?

On output, in effect, the thead and tfoot sections are repeated for each page. The tables were designed this way specifically to take advantage of this. We allow for page breaks after a tbody. The output may contain several pages.

Thus, the output has sort of a pseudo-thead and pseudo-tfoot on each page. But I see no way of using such to mark the first tbody on a page. Any ideas? Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等你爱我 2024-09-17 04:39:39

似乎没有任何文档讨论基于 @page 创建的“页面框”定位 css 的可能性。所有内容都讨论了 @page 如何创建“页面框”,但没有讨论如何访问或指向该页面框以设置页面上子元素的样式。这些都是在黑暗中拍摄的,未经测试的,并且可能无效,但也许......

@page tbody:first-child tr.row-to-style { styles go here }

或者也许使用命名页面?比如:

@page nameOfPage {}
tbody:first-child tr.row-to-style {page: nameOfPage; other styles go here}

或者类似 @media 定义:

@page {
    tbody:first-child tr.row-to-style { styles go here}
}

或者也许(因为我假设内容是在每个页面上为 theadtfoot 生成的,这应该理论上将 thead 放在每个页面的第一个 tbody 之前):

thead + tbody tr.row-to-style { styles go here }

老实说,我不希望这些方法起作用,但你可以尝试一下。问题似乎是真正的 tfoot 仅在 source 的顶部定义一次,因此 css 选择器无法将生成的页面识别为出于样式目的而存在。

There just doesn't seem to be any documentation that talks about the possibility of targeting css based off the "page box" that the @page creates. Everything talks about how the @page creates a "page box" but nothing about how to access or point to that page box for styling of child elements on a page. These are all shots in the dark, untested, and likely not valid, but maybe...

@page tbody:first-child tr.row-to-style { styles go here }

Or perhaps some use of named pages? Like:

@page nameOfPage {}
tbody:first-child tr.row-to-style {page: nameOfPage; other styles go here}

Or something like @media defining:

@page {
    tbody:first-child tr.row-to-style { styles go here}
}

Or maybe (since I assume the content is generated on each page for thead and tfoot, which should theoretically place thead before the first tbody of each page):

thead + tbody tr.row-to-style { styles go here }

Honestly, I don't expect any of these to work, but you can give them a try. The problem seems to be that the real tfoot is only defined once at the top of the source and therefore the css selectors do not recognize the page generated one's as existing for styling purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文