How to set margins 0 on print preview?

帅比萌擦擦* 提交于 2019-12-20 09:37:15

问题


Where am i doing wrong?

This is the normal print preview:

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

This is the css codes and preview:


回答1:


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.




回答2:


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.




回答3:


Thanks ! works well on chrome

@page {
    margin: 0;
}



回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/952607/how-to-set-margins-0-on-print-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!