Print Light-Colored Text as Dark Text in Chrome

旧城冷巷雨未停 提交于 2020-01-25 03:24:22

问题


I am developing a web page that has light colored text on a dark background. When I try to print the page in black and white, the browser seems to automatically be inverting the colors so that it doesn't take a full cartridge to print. This is exactly what I was hoping for.

When I try to print in Firefox, the text is converted to a fully solid black. In Chrome, however, the text appears faint, and that is making it hard to read. Chrome still prints page numbers, time stamps, etc in the full solid black. How can I get Chrome to print the text on my page in that same full solid black?

Here's a sample showing the exact colors I'm using, and it reproduces the behavior I'm seeing on my actual page.

<body>
    <form id="form1">
    <div>
        <table style="background-color:#2D3541; width:900px; height:900px">
            <tr>
                <td style="font-size:medium; text-align:center; color:#B7DBFF">Sample Text</td>
            </tr>
        </table>
    </div>
    </form>
</body>

回答1:


What you can do is create what's known as a Print Stylesheet. This is a normal css stylesheet loaded in only when the user tries to print the web page in question. Normally browsers will aim to ignore certain CSS attributes which could lead to large amounts of ink being wasted (say the page has a background colour) and convert text to darker colours by assuming the background is white.

This can be overridden by creating a new print stylesheet <link rel="print" href="/css/print.css" or using media query @media print {...}

I find using a separate print stylesheet preferential as browsers won't load it until the user is intending to print the page.

by specifying the color of the the text that's causing issue in your print stylesheet or media query, you should be able to resolve issues where browsers aren't picking up your text style rules. If you're overriding a value set in another stylesheet, experiment with the use of !important if using a print stylesheet alone doesn't help things.

Ideally you should give your td a class to give you more granular control. Values in the style attribute take a higher priority than stylesheets, and Chrome may still be honouring the inline style attribute when the page is printed.

@media print {
    .light {
        color: #000 !important;
    }
}

Smashing Magazine has some great resources on print styles:

https://www.smashingmagazine.com/2011/11/how-to-set-up-a-print-style-sheet/



来源:https://stackoverflow.com/questions/35630372/print-light-colored-text-as-dark-text-in-chrome

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