css – html页面中的自定义页眉和页脚

前端之家收集整理的这篇文章主要介绍了css – html页面中的自定义页眉和页脚前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在打印模式下将页眉和页脚放在每个页面中.我做了很多研究.

我找到了两个解决方案.但它们不是跨浏览器(我希望它能在IE,Firefox和Chrome中运行)

第一个解决方案:我在内容表的顶部和底部设置边距.然后我用固定位置写这个空间的页眉和页脚.它在Firefox中运行良好.但在IE和Chrome中并没有设定利润率.同样在Chrome中,它不会为每个页面编写页眉和页脚.

这是我的代码

pagination.PHP

  1. <!DOCTYPE HTL>
  2. <html>
  3. <head>
  4. <Meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
  5. <Meta name="robots" content="noindex,nofollow">
  6. <Meta name="googlebot" content="noindex">
  7. <Meta http-equiv="cache-control" content="no-cache">
  8. <title>Brove.NET ISO Yazılımı</title>
  9. <link rel="stylesheet" type="text/css" href="css/pagination.css" />
  10. </head>
  11.  
  12. <body>
  13. <table class="header" cellpadding="0" cellspacing="0">
  14. <tr>
  15. <td>header
  16. </td>
  17. </tr>
  18. </table>
  19.  
  20. <table class="content" cellpadding="0" cellspacing="0">
  21. <tr>
  22. <td valign="top">
  23. content
  24. </td>
  25. </tr>
  26. </table>
  27.  
  28. <table class="footer" cellpadding="0" cellspacing="0">
  29. <tr>
  30. <td>footer
  31. </td>
  32. </tr>
  33. </table>
  34.  
  35. </body>
  36. </html>

pagination.css

  1. @media screen{
  2. .header{
  3. width:768px;
  4. height:100px;
  5. border:2px solid #000;
  6. }
  7.  
  8. .content{
  9. width:768px;
  10. margin-top:10px;
  11. margin-bottom:10px;
  12. height:1000px;
  13. }
  14.  
  15. .footer{
  16. width:768px;
  17. height:100px;
  18. border:2px solid #000;
  19. }
  20. }
  21.  
  22. @media print {
  23. .header{
  24. position:fixed;
  25. top:0;
  26. left:0;
  27. width:768px;
  28. height:100px;
  29. border:2px solid #000;
  30. }
  31.  
  32. .content{
  33. width:768px;
  34. margin-top:120px;
  35. margin-bottom:120px;
  36. height:1000px;
  37. }
  38.  
  39. .footer{
  40. position:fixed;
  41. left:0;
  42. bottom:0;
  43. width:768px;
  44. height:100px;
  45. border:2px solid #000;
  46. }
  47.  
  48. @page{
  49. margin-bottom:150px;
  50. }
  51. }

这是第二个解决方案:

在此解决方案中,我使用table-header-group和table-footer-group属性.它适用于Firefox和IE.但Chrome不再理解.在打印模式下,它不会在每个页面中重复页眉和页脚.

这是另一个代码Is there a way to get a web page header/footer printed on every page?

  1. <style type="text/css">
  2. thead { display: table-header-group; }
  3. tfoot { display: table-footer-group; }
  4. </style>
  5.  
  6. <body>
  7. <table>
  8. <thead><tr><td>Your header goes here</td></tr></thead>
  9. <tfoot><tr><td>Your footer goes here</td></tr></tfoot>
  10. <tbody>
  11. <tr><td>
  12. Page body in here -- as long as it needs to be
  13. </td></tr>
  14. </tbody>
  15. </table>
  16. </body>

是否有任何黑客可以解决这个浏览器问题,或者您对我有什么建议吗?

解决方法

尝试使用div标签而不是任何表标签创建页面! div比表重量轻
  1. <div id='header' style='height:230px'>
  2. </div>
  3.  
  4. <div id='body'></div>
  5.  
  6. <div id='footer' style='height:230px'>
  7. </div>

谢谢 !

猜你在找的CSS相关文章