How do I Make Firefox Print a Background-Color Style?

后端 未结 8 1059
臣服心动
臣服心动 2020-11-29 08:14

I have some simple CSS:

#someElement {
    background-color:black;
    color:white;
}

It looks ok in the browser, but when I go to print it

8条回答
  •  情书的邮戳
    2020-11-29 09:01

    There is a simple solution for this.

    For background-color, instead of using:

    background-color: red
    

    Use:

    background-color: unset;
    box-shadow: inset 0 0 0 1000px red /* 1000px is a random high 
                                         number that is definitely 
                                         larger than the box dimension*/
    

    Also for color, instead of:

    color: grey;
    

    Use:

    color: unset;
    text-shadow: 0 0 grey;
    

    You may restrict them to print only by using @media print, but you do not have to!


    Note: Sometimes you should use background-color: transparent; or color: transparent; if the color or background-color are inherited from parent elements.

提交回复
热议问题