如何将打印预览的页边距设置为0?

发布于 2024-07-23 20:22:29 字数 386 浏览 11 评论 0原文

我哪里做错了?

这是正常的打印预览: 这是第一个图片

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

这是CSS代码和预览:

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:

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暗喜 2024-07-30 20:22:29

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

@page {
    margin: 0;
}

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

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.

失退 2024-07-30 20:22:29

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

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

天煞孤星 2024-07-30 20:22:29

谢谢 ! 在 Chrome 上运行良好

@page {
    margin: 0;
}

Thanks ! works well on chrome

@page {
    margin: 0;
}
心在旅行 2024-07-30 20:22:29

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

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

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.

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.

蓝眼睛不忧郁 2024-07-30 20:22:29

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

我发现在 IE8 上,页边距始终至少为左右 6.01 毫米,顶部和底部 5 毫米。 无论我做什么,即使在@page规则中使用@top-left right和center规则,它仍然默认为上面的值。

创建样式表以考虑打印尺寸的这一限制可能会更容易。

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

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

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

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

I found that on IE8, page margins will always be a minimum of 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.

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:

.aDiv {
    margin: 10mm;
    margin: 15mm\9;     //this \9 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文