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

发布于 2024-12-27 21:13:13 字数 3072 浏览 1 评论 0原文

我想在打印模式下将页眉和页脚放在每一页中。我对此做了很多研究。

我找到了两个解决方案。但它们不是跨浏览器的(我希望它能在 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-grouptable-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>

有没有办法解决这个浏览器问题,或者您对我有什么建议吗?

I want to put header and footer in every page at print mode. I've done many research about that.

I've find two solution. But they aren't cross-browser ( I want it to work in IE, Firefox and Chrome)

The first solution : I am setting margins on the top and bottom to my content table. Then i write header and footer to this spaces with fixed position. It is working perfect in Firefox. But in IE and Chrome It doesnt set margins. Also in Chrome it doesnt write header and footer to every page.

Here is my code:

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;
    }
}

And this is the second solution :

In this solution im using table-header-group and table-footer-group attributes. It works Firefox and IE. But Chrome doesnt understand again. It doesnt repeat header and footer in every page on print mode.

Here is another code : 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>

Is there any hack to solve this browser problems or do you have any suggestion to me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大姐,你呐 2025-01-03 21:13:13

尝试在 div 标签而不是任何表格标签中创建页面! div 比 table 更轻

<div id='header' style='height:230px'>
</div>

<div id='body'></div>

<div id='footer' style='height:230px'>
</div>

谢谢!

Try to create your page in div tag rather than any table tag ! div is more light weight than table

<div id='header' style='height:230px'>
</div>

<div id='body'></div>

<div id='footer' style='height:230px'>
</div>

Thank You !

冰葑 2025-01-03 21:13:13

在我看来,这个网站有 een api 和许多选项,例如自定义页眉和页脚,非常适合打印:

http://pdfmyurl.com< /a>

就我而言,速度非常好,并且不会改变布局中的任何内容。

解决方案二(大量工作):
对所有元素使用绝对定位。

In my opinion this website which has een api and many options such as custom header and footer works great for printing:

http://pdfmyurl.com

In my case the speed is excellent and it doesn't change anything in the layout.

Solution two (lot of work):
Use absolute positioning on all elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文