CSS 如何在打印预览中设置边距 0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/952607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:40:23  来源:igfitidea点击:

How to set margins 0 on print preview?

cssinternet-explorermargins

提问by uzay95

Where am i doing wrong?

我哪里做错了?

This is the normal print preview: this is the first picture

这是正常的打印预览: 这是第一张照片

But I want to see this picture (without dragging margin arrows) alt text

但我想看这张图(不拖动边距箭头) 替代文字

This is the css codes and preview:

这是css代码和预览:

alt text

替代文字

采纳答案by Randolpho

The best you can do is set @pagemargins. Keep in mind, however, that you can and most likely will be overruled if you set margins to 0.

您能做的最好的事情就是设置@page边距。但是请记住,如果您将边距设置为 0,您可以而且很可能会被否决。

回答by Chris B.

Yes. It is possible to alter your margins in a page printout. The rule would look like:

是的。可以在页面打印输出中更改页边距。该规则如下所示:

@page {
    margin: 0;
}

This will not work in Firefox as of now. If you check their developer reference on the @page CSS support, you can see what browsers do support @page.

到目前为止,这在 Firefox 中不起作用。如果您在@page CSS 支持上查看他们的开发人员参考,您可以看到哪些浏览器支持@page

回答by Yair Yaya Tendler

Thanks ! works well on chrome

谢谢 !在 chrome 上运行良好

@page {
    margin: 0;
}

回答by David John Welsh

I don't think it is actually possible to do this, because you'd be overruling the defaults on the user's computer. As far as I know, a web application doesn't have the access rights to alter something like printer settings without some kind of ActiveX script in IE.

我认为这实际上是不可能的,因为您会否决用户计算机上的默认设置。据我所知,如果没有 IE 中的某种 ActiveX 脚本,Web 应用程序没有访问权限来更改诸如打印机设置之类的内容。

I had a similar problem a while back, and ended up having to generate a PDF on the fly using TCPDF. In the end that worked out better, because you have greater control over the layout.

不久前我遇到了类似的问题,最终不得不使用 TCPDF 动态生成 PDF。最终效果更好,因为您可以更好地控制布局。

回答by Rafael Ventura

I'm prevented from upgrading a computer from Windows XP to something more recent, so basically I'm stuck with IE8.

我无法将计算机从 Windows XP 升级到更新版本,因此基本上我只能使用 IE8。

I found that on IE8, page margins will always be a minimumof 6.01mm left and right, and 5mm top and bottom. No matter what I do, even using @top-left right and centre rules inside the @page rule, it will still default to the values above.

我发现在 IE8 上,页边距始终至少为 6.01mm 左右,5mm 上下。不管我做什么,即使在 @page 规则中使用 @top-left right 和 center 规则,它仍然会默认为上面的值。

It may be easier to create the stylesheet to take into consideration this limitation on the print size.

考虑到打印大小的这种限制,创建样式表可能会更容易。

It may also help to put the IE hack \9 in front of the CSS class property value, duplicating the property may also help in some cases, (but won't affect the margins of the page), such as:

将 IE hack \9 放在 CSS 类属性值前面可能也有帮助,在某些情况下复制属性也可能有帮助(但不会影响页面的边距),例如:

.aDiv {
    margin: 10mm;
    margin: 15mm;     //this  hack will set that value only on IE8.
}

I know there are other hacks similar to this, such as \0 but I admit don't fully understand them. \9 works for me in IE8 in some situations.

我知道还有其他类似的黑客攻击,例如 \0 但我承认不完全理解它们。\9 在某些情况下在 IE8 中对我有用。