【问题标题】:css3 page media not working in any browsercss3页面媒体在任何浏览器中都不起作用
【发布时间】:2019-09-12 21:19:54
【问题描述】:

您好,我使用 CSS3 page media module 直接从浏览器将 html 内容打印到 PDF,但我没有使用任何浏览器来处理它。我的工作在下面。

<!DOCTYPE html>
<html lang="en">
<head>
<style>
@media print {

body {
        margin: 0;
        padding: 0;
        background-color: #FAFAFA;
        font: 12pt "sans-serif";
        position: relative;
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }


        @page {
            size: letter;
            margin: 20mm 25mm;
        }
        @page {
            @top-center {
                content: element(pageHeader);
            }
        }

        @page  {
            @bottom-center {
                content: element(pageFooter);
            }
        }
        #pageHeader {
          position: running(pageHeader);
        }
        #pageFooter{
          position: running(pageFooter);
        }

    }
</style>
</head>
<body>
<div id="pageHeader">
    <p>This is the Header shown on first page.</p>
</div>
<div id="pageFooter">
    <p>This is the footer shown on last page.</p>
</div>
<section class="page"> 

<h1>Introduction</h1>
<p>The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:</p>

<p>
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:

</p>
<p>The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:</p>


 </section>


 </body>
</html>

它不适用于我的任何浏览器。我已经在最新的 Chrome、FF、Opera、Safari 中对其进行了测试。它应该在每一页上显示页眉和页脚。页眉旨在显示在每个页面的顶部,而页脚则显示在每个页面的底部。任何人都可以有实际工作的 CSS3 页面媒体模块元素的工作示例。此外,我不是在寻找绝对位置或页眉和页脚的固定解决方案。我试过了,除了单页外,它不起作用。我已经为这个问题缩短了我的文本内容,但它可以被复制和过去以生成多页文档以查看没有页眉和页脚的多个页面。页眉和页脚 div 保持在顶部。

【问题讨论】:

  • 我想要这个。 :] 我正在寻找此功能支持。

标签: html css printing-web-page css-paged-media css-gcpm


【解决方案1】:

目前任何最终用户浏览器都不支持它,但它在用于生成 PDF 的专用引擎 PrinceXML 中受支持。见the CSS3 support for Margin boxes

PrinceXML 是一个商业产品,但我用它来从 HTML 源创建小说的印刷版本。它支持打印相关功能的完整列表。 (我与他们没有任何关系。)

【讨论】:

    【解决方案2】:

    可能是因为该规范来自 W3C 工作草案而不是实际实现,所以还没有浏览器实现这个提议的规范?事实上,它甚至还没有被提出——它正在作为“工作草案”进行讨论,这意味着它可以进行讨论,甚至还没有成为“编辑草案”。从那里开始,您可能还需要一段时间才能在浏览器中看到它。该工作草案也有一个相对较新的日期 - 2014 年 5 月 13 日 - 所以要注意在一段时间内实施任何该提案。也就是说,这看起来确实是一个方便的补充。

    现在,使用 CSS 伪元素 'before' 或 'after' 以及该标题位置的标签怎么样?

    这里很好地描述了工作草稿和编辑草稿之间的区别: What is the difference between a W3C Working Draft and an Editor's Draft?

    【讨论】:

    猜你喜欢
    • 2016-08-14
    • 1970-01-01
    • 2017-06-26
    • 2017-04-20
    • 2011-04-24
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    相关资源
    最近更新 更多