Printing background-color in Firefox and IE

前端 未结 5 1161
执念已碎
执念已碎 2020-12-29 05:27

I am with some problems to print background-color in Firefox and IE. For Google Chrome I found the follow hack and it works well, but for Firefox and IE I can\'t find anythi

相关标签:
5条回答
  • 2020-12-29 06:09

    For Firefox

    color-adjust:exact;
    

    will work same as -webkit-print-color-adjust:exact;

    0 讨论(0)
  • 2020-12-29 06:12

    For Firefox on the Print dialog there is an Advanced or Show Details button, if you click that , under Appearance there are two checkboxes. One for Print Background Colors and Print Background Images.

    0 讨论(0)
  • 2020-12-29 06:14
    * {
    -webkit-print-color-adjust: exact;
    printer-colors: exact;
    color-adjust: exact;}
    

    Browsers: Chrome, Safari, FireFox

    More: https://wiki.csswg.org/ideas/print-backgrounds

    0 讨论(0)
  • 2020-12-29 06:15

    If you are OK with having your element being a fixed height/width, you can set its size, put a 1px coloured image into it (of whatever colour you want the background to be) and make it fill the space. Then you can absolutely position your content on top.

    <div style="position: relative; width: 100px; height: 100px;">
        <img src="/images/blue.png" style="width: 100px; height: 100px;">
        <div style="position: absolute; top: 0px; left: 0px;">
            Hello world
        </div>
    </div>
    

    Or you could do the same thing with a border instead of an image:

    <div style="position: relative; width: 100px; height: 100px;">
        <div style="width: 0; height: 0; border: 50px solid black;">
        <div style="position: absolute; top: 0px; left: 0px;">
            Hello world
        </div>
    </div>
    

    (Original idea from here: https://defuse.ca/force-print-background.htm)

    0 讨论(0)
  • Seems impossible, as Spark says, but you can sometime use wide borders as workaround (e.g. div with 0 height and 100px border).

    0 讨论(0)
提交回复
热议问题