简体   繁体   English

打印时如何使用 CSS 使 div 占据整个 A4 页面?

[英]How can I use CSS to make a div take up an entire A4 page when printing?

I've been messing around with this for hours now and it's driving me nuts.我已经搞了几个小时了,这让我发疯了。 Unless I'm misunderstanding something, this should be straightforward:除非我误解了什么,否则这应该很简单:

div.A4.page {
          width: 200mm;
          height: 287mm;
          margin: 0;
          border: 5mm solid red;
          padding: 0;
      }

An A4 page is 210mm wide and 297mm high. A4 纸宽 210 毫米,高 297 毫米。 So set to 200mmx287mm with a 5mm border, that should take up the entire page if I do a print preview (set to "print to PDF" with no margins in the print dialog).所以设置为 200mmx287mm 和 5mm 边框,如果我进行打印预览(设置为“打印到 PDF”,在打印对话框中没有边距),它应该占据整个页面。

However, for some reason it's slightly too small.但是,由于某种原因,它有点太小了。 If I set the border to 10mm, then it seems wide enough but not tall enough.如果我将边框设置为 10 毫米,那么它看起来足够宽但不够高。

What's going on here?这里发生了什么? Am I missing something obvious or is the browser implemenation just bad?我是否遗漏了一些明显的东西,或者浏览器的实现很糟糕? (Chromium). (铬)。

Any help appreciated.任何帮助表示赞赏。

Try setting the box-sizing property to content-box尝试将 box-sizing 属性设置为 content-box

div.A4.page {
          width: 200mm;
          height: 287mm;
          margin: 0;
          padding: 0;
          border: 5mm solid red;
          box-sizing:content-box;
      }

Or或者

div.A4.page {
          width: 100%;
          height: 100%;
          margin: 0;
          padding: 0;
          border: 5mm solid red;
          box-sizing:border-box;
      }

However this may be that your printer options have a set margin by default that you need to remove, most printers leave a margin around the A4 page但是,这可能是您的打印机选项默认设置了需要删除的边距,大多数打印机在 A4 页面周围留有边距

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使div占用页面的整个宽度 - Make a div take up the entire width of the page 使导航栏占用css中的整个页面高度 - Make navigation bar take up entire page height in css 在多页上打印时,如何使HTML表格页脚占据每页上的可用空间? - How can I make HTML table footer take available space on each page when printing on multiple pages? 当一个div处于宽度为90%的另一个div内时,如何使div占据页面的整个宽度 - How can I make a div take the full width of the page when it is inside another div that have 90% width 当内容不占用整个页面时,CSS Sticky Footer - CSS Sticky Footer when content does not take up entire page 如何在将鼠标悬停在另一个元素上时显示一个元素,如果没有则隐藏它。 让它一直占据空间 - How can I make a element show when hovering over another element, and hide it if not. And make it take up space the entire time 如何使DIV占用页面的其余部分? - How to make a DIV take up the remainder of the page? 如何使图像占据整个div的高度和宽度? - How to make an image take up an entire div height and width? 使用position absolute时如何使vue组件中的div占据整个屏幕? - How to make a div in a vue component take up the entire screen when using position absolute? 如何在整个页面上设置div的背景 - How can I make background of a div span over the entire page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM