How to set margins 0 on print preview?

前端 未结 5 855
花落未央
花落未央 2021-02-01 19:04

Where am i doing wrong?

This is the normal print preview:

相关标签:
5条回答
  • 2021-02-01 19:26

    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.

    0 讨论(0)
  • 2021-02-01 19:31

    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.

    0 讨论(0)
  • 2021-02-01 19:33

    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.

    0 讨论(0)
  • 2021-02-01 19:36

    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.

    0 讨论(0)
  • 2021-02-01 19:37

    Thanks ! works well on chrome

    @page {
        margin: 0;
    }
    
    0 讨论(0)
提交回复
热议问题