[英]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.