• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

当内容在多个页面上时,CSS打印自定义大小的页面边距

用户头像
it1352
帮助1

问题说明

我正在尝试打印一个可能很长的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?

在打印预览屏幕中可见

正确答案

#1

请尝试以下操作:

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcebbjk
系列文章
更多 icon
同类精品
更多 icon
继续加载