我想在打印模式下将页眉和页脚放在每个页面中 . 我做了很多研究 .
我找到了两个解决方案 . 但它们不是跨浏览器(我希望它能在IE,Firefox和Chrome中运行)
第一个解决方案:我在内容表的顶部和底部设置边距 . 然后我用固定位置写这个空间的页眉和页脚 . 它在Firefox中运行良好 . 但在IE和Chrome中并没有设定利润率 . 同样在Chrome中,它不会为每个页面编写页眉和页脚 .
这是我的代码:
pagination.php
<!DOCTYPE HTL>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex">
<meta http-equiv="cache-control" content="no-cache">
<title>Brove.NET ISO Yazılımı</title>
<link rel="stylesheet" type="text/css" href="css/pagination.css" />
</head>
<body>
<table class="header" cellpadding="0" cellspacing="0">
<tr>
<td>header
</td>
</tr>
</table>
<table class="content" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
content
</td>
</tr>
</table>
<table class="footer" cellpadding="0" cellspacing="0">
<tr>
<td>footer
</td>
</tr>
</table>
</body>
</html>
pagination.css
@media screen{
.header{
width:768px;
height:100px;
border:2px solid #000;
}
.content{
width:768px;
margin-top:10px;
margin-bottom:10px;
height:1000px;
}
.footer{
width:768px;
height:100px;
border:2px solid #000;
}
}
@media print {
.header{
position:fixed;
top:0;
left:0;
width:768px;
height:100px;
border:2px solid #000;
}
.content{
width:768px;
margin-top:120px;
margin-bottom:120px;
height:1000px;
}
.footer{
position:fixed;
left:0;
bottom:0;
width:768px;
height:100px;
border:2px solid #000;
}
@page{
margin-bottom:150px;
}
}
这是第二个解决方案:
在此解决方案中我使用 table-header-group
和 table-footer-group
属性 . 它适用于Firefox和IE . 但Chrome不再理解 . 在打印模式下,它不会在每个页面中重复页眉和页脚 .
这是另一个代码:Is there a way to get a web page header/footer printed on every page?
<style type="text/css">
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
</style>
<body>
<table>
<thead><tr><td>Your header goes here</td></tr></thead>
<tfoot><tr><td>Your footer goes here</td></tr></tfoot>
<tbody>
<tr><td>
Page body in here -- as long as it needs to be
</td></tr>
</tbody>
</table>
</body>
是否有任何黑客可以解决这个浏览器问题,或者您对我有什么建议吗?
2 回答
尝试使用div标签而不是任何表标签创建页面! div比表重量轻
谢谢 !
在我看来,这个网站有een api和许多选项,如自定义页眉和页脚非常适合打印:
http://pdfmyurl.com
在我的情况下,速度非常好,它不会改变布局中的任何内容 .
解决方案二(很多工作):对所有元素使用绝对定位 .