【问题标题】:Margin not working on the second page边距在第二页上不起作用
【发布时间】:2017-07-11 14:11:44
【问题描述】:

我有一个显示公司规则的网站。它有多个章节、标题、副标题和内容。我想制作一个可打印的版本,如下所示:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<style type="text/css">
   @media screen {
    header.onlyprint, footer.onlyprint{
        display: none; /* Hide from screen */
    }`enter code here`
}

@media print {
    header.onlyprint {
        position: fixed; /* Display only on print page (each) */
        top: 0; /* Because it's header */
    }
    footer.onlyprint {
        position: fixed;
        bottom: 0; /* Because it's footer */
    }
}
</style>
</head>
<body>
<header class="onlyprint">header</header>
<!--long text-->
<footer class="onlyprint">footer</footer>
</body>
</html>

这使我可以在每一页上显示标题。问题是, - 因为内容就像一个大块 - 如果我设置一个 margin-top,在第一页上它可以工作,但在第二页上,文本的延续直接从顶部开始,并且标题重叠它.我看到其他一些有同样问题的帖子,但答案总是他们应该把内容切碎。对我来说,那不是选项,因为公司有很多规则,页面只显示给定的规则。对不起我的英语,希望你明白我的问题是什么

【问题讨论】:

    标签: html css printing margin


    【解决方案1】:

    尝试将页边距添加到页面本身:

    @page {
        margin: 50px 0;
    }
    

    【讨论】:

    • 只在首页有效。
    • 刷新所有缓存?也许它被缓存了。
    • 是的。我使用与上面编写的相同的代码进行测试,使用lipsum来模拟内容。
    猜你喜欢
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    相关资源
    最近更新 更多