当内容在多个页面上时,CSS打印自定义大小的页面边距 [英] CSS print a custom sized page margin when the content is on multiple pages

查看:448
本文介绍了当内容在多个页面上时,CSS打印自定义大小的页面边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印一个可能很长的HTML页面,其中包含文本段落和表格。我的目标是为每页定义一个打印边距。
我在页面上添加了以下CSS:

I'm trying to print an HTML page that might be long and contain text paragraphs and tables. My goal is to define a print margin for every page. I added the following CSS to my page:

@media print {
    body {
        margin: 2.5cm 0;
    }
}

但是我的问题是保证金得到了仅在文档的开头和结尾添加了,而不是在每个页面上都添加了。
从所附图像中可以看到,我在第一页中有一个页边距的顶部,但在第二页中却没有,我想要的行为类似于一本书或word文档(您在其中定义页边距)。
是否可以在CSS中完成?

But the problem that I have is that the margin gets added only to the beginning and end of the document and NOT to every single page. As you can see from the attached image I have a margin top in the first page but not in the second one, my desired behavior is something similar to a book or a word document (where you define page margins). Is it possible to do it in CSS?

在打印预览屏幕中可见

推荐答案

请尝试以下操作:

@media print {
   body {
   display:table;
   table-layout:fixed;
   padding-top:2.5cm;
   padding-bottom:2.5cm;
   height:auto;
    }
}

这篇关于当内容在多个页面上时,CSS打印自定义大小的页面边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆