打印html页面时的边距 [英] Margin while printing html page

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

问题描述

我使用单独的样式表进行打印。可以在设置打印边距(即纸张边距)的样式表中设置右边距和左边距。

I am using a separate style-sheet for printing. Is it possible to set right and left margin in the style-sheet which set the print margin (i.e. margin on paper).

谢谢。

推荐答案

您应该使用 cm mm 作为单位指定打印时。使用像素将导致浏览器将其翻译成类似于它在屏幕上的外观。使用 cm mm 将确保纸张尺​​寸一致。

You should use cm or mm as unit when you specify for printing. Using pixels will cause the browser to translate it to something similar to what it looks like on screen. Using cm or mm will ensure consistent size on the paper.

body
{
  margin: 25mm 25mm 25mm 25mm;
}

对于字体大小,请使用 pt

For font sizes, use pt for the print media.

请注意,以css样式设置主体上的页边距将调整打印机驱动程序中的页边距定义打印机的可打印区域,或由浏览器控制的边距(在某些浏览器的打印预览中可调)...它只是在可打印区域中的文档上设置边距。

Note that setting the margin on the body in css style will not adjust the margin in the printer driver that defines the printable area of the printer, or margin controlled by the browser (may be adjustable in print preview on some browsers)... It will just set margin on the document inside the printable area.

您还应该注意,IE7 ++会自动调整大小以使其最佳,并且即使使用 cm mm 。要覆盖此行为,用户必须选择打印预览,然后将打印尺寸设置为 100%(默认值为缩小到适合)。

You should also be aware that IE7++ automatically adjusts the size to best fit, and causes everything to be wrong even if you use cm or mm. To override this behaviour, the user must select 'Print preview' and then set the print size to 100% (default is Shrink To Fit).

完全控制打印边距的更好选项是使用 @page 指令设置纸张边距,这将影响html body元素外面的纸张边距,这通常由浏览器控制。请参见 http://www.w3.org/TR/1998 /REC-CSS2-19980512/page.html

此选项目前适用于除Safari之外的所有主要浏览器。

在Internet Explorer中,边距实际上设置为值,并且如果您执行预览,您将获得此默认值,但用户可以在预览中更改它。

A better option for full control on printed margins is to use the @page directive to set the paper margin, which will affect the margin on paper outside the html body element, which is normally controlled by the browser. See http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html.
This currently works in all major browsers except Safari.
In Internet explorer, the margin is actually set to this value in the settings for this printing, and if you do Preview you will get this as default, but the user can change it in the preview.

@page  
{ 
    size: auto;   /* auto is the initial value */ 

    /* this affects the margin in the printer settings */ 
    margin: 25mm 25mm 25mm 25mm;  
} 

body  
{ 
    /* this affects the margin on the content before sending to printer */ 
    margin: 0px;  
} 

相关答案:
从页面中停用浏览器打印选项(标题,页脚,页边距)

Related answer: Disabling browser print options (headers, footers, margins) from page?

这篇关于打印html页面时的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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