【问题标题】:HTML footer at the last printed page最后打印页面的 HTML 页脚
【发布时间】:2015-02-11 10:23:43
【问题描述】:

我想打印我的 html 页面。我有超过 1 页,我只想在最后一页的底部打印我的页脚。我的CSS

@page {
        size: 8.5in 11.0in;
        margin-left: 0.7cm;
        margin-top: 0.7cm;
        margin-top: 0.7cm;
        margin-bottom: 2.6cm;
        margin-right: 0.5cm
    }

#footer {
        clear: both;
        position: running(footer);
        z-index: 10;
        margin-top: -1em;
        vertical-align: bottom;
        height: 5%;
    }

 @page {
        @bottom-center {
            content: element(footer);
        }
    }

HTML:

<body><div id="content"></div>
       <div id="footer"></div>
<body>

它有效,但是当我的内容最后有非常大的表格时,例如 6 页表格,我的页脚会填充所有带有表格的页面。

【问题讨论】:

    标签: html css pdf-generation


    【解决方案1】:

    已解决:下面的 CSS 代码将仅在 PDF 的最后一页显示页脚或任何内容。

    <style type="text/css" media="print">    
        @page {    
            size: A4 portrait;    
            padding-left: 8px;    
            padding-right: 0px;
            margin-top: 50px;
            margin-bottom: 150px;
        
            @bottom-center {width: 100%; content: element(footer)}
        }  
        
        @media print {
            .footer {
                left: 0;
                width: 100%;
                position: running(footer);
                height: 200px;
            }  
        }
    </style>
    
    
    
    <div class="footer">
        Content Here
    </div>
    

    【讨论】:

      【解决方案2】:

      为了更简单,您可以将页脚放置在媒体查询中,以便以另一种方式打印:

      @media print { 
      body {
        position: relative;
        }
      #printfooter {
        position: absolute;
        bottom: 0;
        }
      }
      

      作为一个快速解决建议。或者您使用带有 @page 扩展名的 css3:

      @page:last {
          @bottom-center {
              content: element(footer);
          }
      }
      

      更多信息 w3 有一个关于CSS Paged Media Modules 的非常好的纪录片。 5.3,示例 7 是您可以使用的信息!

      希望其中之一有所帮助!如果,或者如果不是,请告诉我。

      最好的问候, 玛丽安。

      【讨论】:

      • 不幸的是,@page 规则没有 :last 伪类。
      猜你喜欢
      • 2010-11-13
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 2020-07-29
      • 2023-03-24
      • 1970-01-01
      • 2011-11-01
      • 2012-04-07
      相关资源
      最近更新 更多