我试图在加载页面时打印一个页面,并且我一直试图使用@media print在CSS中打印页面,但是无论我做什么,我都无法让它工作。
我唯一需要做的就是在<th>标签中应用颜色。
HTML代码:
<body onload="window.print();">
<div>
<h2 class="text-center"><span class="label label-default">Order Form Details</span></h2><br>
<table class="table table-hover table-responsive">
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Telephone</th>
<th>Postal Code</th>
<th>Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
</body>CSS代码:
th {
background-color: #C8C8C8;
}JSFiddle 这里
发布于 2017-09-23 16:23:47
这取决于浏览器设置,但大多数浏览器默认不会打印背景色(您可以将其设置为“做”,但只能在浏览器本身,即打开页面的用户中打印),而且默认情况下不能强迫它们这样做,因为它是网站代码对其没有影响的浏览器设置。
如果您绝对需要它,您必须将其编码为img标记,并将其放在DIV后面。
发布于 2017-09-23 15:36:30
您可以在css中使用@media打印
.table th {
background-color: #C8C8C8;
-webkit-print-color-adjust: exact;
}
@media print {
.table th { background-color: #C8C8C8 !important; }
}https://stackoverflow.com/questions/46381236
复制相似问题