固定每个打印页面上的页眉并避免页脚中的分页符

问题描述

在我的页面中有三个 Div,分别是 invoiceHeader、invoiceBody 和 invoiceFooter。我想在每个打印页面上重复第一个 div (.invoiceHeader),并且我想避免在打印时在 thired Div (.invoiceFooter) 内部分页页面上将没有页脚。我该怎么做?

解决方法

以下代码可以帮助您作为打印的粘性页眉和页脚

@media print { 
    .centerDiv{
        width: 80%;
        margin: 0 auto; /* Center the DIV horizontally */
    }
    .fixed-header,.fixed-footer{
        width: 100%;
        position: fixed;    
    }
    .fixed-header{
        top: 0;
    }
    .fixed-footer{
        bottom: 0;
    } 

}