【问题标题】:Adding header for dynamic pages on print在打印时为动态页面添加页眉
【发布时间】:2017-02-25 08:08:13
【问题描述】:

我有多个动态填充的表格。

我想在打印模式下在每一页上打印页眉,但是当表格行不适合页面时,它们会打印在下一页上,而我的页眉会打印在上面。 像这样:This is my print preview

如何设置页眉和页面数据之间的边距?

我搜索了很多,但似乎没有任何效果,甚至 position:fixed 也没有按预期工作。

 @page {
       size: A4;
       margin-left: 0px;
       margin-right: 0px;
       margin-bottom: 0px;
       margin-top: 0px;
  }
@media screen {
     .header {
         display: none;
      }
  }

@media print {

    .header {
        position: fixed;
        top:10px;
        width:100%;
        margin:10px;
        border: 3px solid #000;
    }
}

HTML 示例:

<table class="header">
    <tr>
        <td>
         This is my header table
        </td>
    </tr>
 </table>

<table>
   ....
</table>

<table>
  ....
</table>

and more...

【问题讨论】:

    标签: html css printing header print-preview


    【解决方案1】:

    您可以简单地在页眉底部添加一个边距。

    @media print {
        .header {
            width:100%;
            margin:10px;
            margin-bottom: 100px;
            border: 3px solid #000;
        }
    }
    

    如果没有它,这将无法与 position: fixed; 结合使用。

    【讨论】:

    • 是的,我试过了,tnx 但不幸的是不起作用
    • @SaMirakf 我试过了。删除 position: fixed; top: 10px; 时,它可以工作。
    • 如果我删除位置:固定标题将打印在一页上,而我想要每一页
    猜你喜欢
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多