FUR*_*GIN 7 css printing google-chrome header footer
我想在打印模式下将页眉和页脚放在每个页面中.我做了很多研究.
我找到了两个解决方案.但它们不是跨浏览器(我希望它能在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>
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
这是第二个解决方案:
在此解决方案中使用table-header-group和table-footer-group属性.它适用于Firefox和IE.但Chrome不再理解.在打印模式下,它不会在每个页面中重复页眉和页脚.
这是另一个代码:有没有办法在每个页面上打印一个网页页眉/页脚?
<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>
Run Code Online (Sandbox Code Playgroud)
是否有任何黑客可以解决这个浏览器问题,或者您对我有什么建议吗?
尝试在 div 标签而不是任何表格标签中创建页面!div 比 table 更轻量
<div id='header' style='height:230px'>
</div>
<div id='body'></div>
<div id='footer' style='height:230px'>
</div>
Run Code Online (Sandbox Code Playgroud)
谢谢 !