gpt4 book ai didi

html - 应用于页眉的样式未应用于打印 View

转载 作者:行者123 更新时间:2023-11-28 00:00:40 25 4
gpt4 key购买 nike

我想用 chrome 打印一张表格。如果单行超出页面范围并为其重复表头,则不会应用表头上应用的样式。

我为该行设置了一个非常大的值,这使得它超出了一个页面并在未正确应用样式的下一页中重复标题。

引用图片:这里的背景颜色不适用于下一页标题 enter image description here

代码网址:https://drive.google.com/file/d/1iAKsBQ82J24r0TJaR9pMiFOtBNax7idq/view?usp=sharing

代码:

<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}

td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
border: 1px solid #dddddd;
text-align: left;
color: red;
}
thead{
color: red;
background-color: blue;
}
tr:nth-child(odd) {
background-color: #dddddd;
}
@media print{
thead{
color: red !important;
background-color: blue !important;
}
}
</style>
</head>
<body>

<h2>HTML Table</h2>

<table>
<thead>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</thead>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma
</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>

</body>
</html>

最佳答案

是的,这是 Webkit/Chrome 的东西。它不会在每一页上打印 thead。要实现这样的目标,您可以做的是使用分页符。

分页符仅适用于 block 元素,因此您应该相应地设置 tr 的样式。

tbody tr.head {
page-break-before: always;
page-break-inside: avoid;
}

引用here .

table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}

td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

th {
border: 1px solid #dddddd;
text-align: left;
color: red;
background-color: blue !important;
}

thead {
color: red;
background-color: blue !important;
}


tr:nth-child(odd) {
background-color: #dddddd;
}
tbody tr.head {
page-break-before: always;
page-break-inside: avoid;
}
@media screen {
tbody .head {
display: none;
}

thead {
color: red !important;
background-color: blue !important;
}
}
@media print {
body {
-webkit-print-color-adjust: exact;
}
}
<h2>HTML Table</h2>

<table>
<thead>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</thead>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma
</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>

关于html - 应用于页眉的样式未应用于打印 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56000641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com