CSS打印样式
我有一个页面在屏幕上显示良好。
我有一个 css,然后它会格式化屏幕以进行打印并重新调整各部分的大小。
我的问题是打印布局距页面左侧大约一英寸的边距,这使得 2 个元素打印在页面右侧。
我可能可以从右侧压缩内容,但我想知道是否可以减少左侧的边距(基本上使内容居中)
我已将打印时的正文标记设置为 margin:0;
padding: 0;
但这没有效果吗?
是否还有其他控制打印边距的设置?
I have a page which displays fine on the screen.
I have a css which then formats the screen for print and re-sizes the sections.
My problem is that the print layout has a margin of approximately an inch from the left of the page which makes 2 elements print off the page on the right hand side.
I could probably compress the contents from the right but I want to know if I can reduce the margin on the left (and basically center the contents)
I have set the body tag on print to margin:0;
padding: 0;
but this has no effect?
Is there another setting that controls print margins?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CSS 设置打印边距(和横向),如下所示:
好消息是,它有效! (在 Chrome 上。其他浏览器不支持,尽管我没有测试 IE9。)
页边距必须采用在打印中有意义的单位——不允许使用像素。
Chrome 不会将边距缩小到固定最小值以下,该最小值可能由打印机驱动程序确定。
You can set the print margin (and landscape orientation) with CSS like:
And the good news is, it works! (On Chrome. Not supported on other browsers though I did not test IE9.)
The margin must be in a unit that makes sense in print -- pixels are not allowed.
Chrome will not shrink the margin below a fixed minimum, which may be determined by the printer driver.
您还可以尝试将
margin:0;
和padding:0;
设置为
html
、main content div
和p
标签,看看是否有帮助。
否则,最好的选择是在元素上设置特定的
宽度
。You could also try to set
margin:0;
andpadding:0;
to the
html
,main content div
andp
tagsand see if that helps.
Otherwise, your best bet is to set a specific
width
on your elements.