Printing Background Images in Firefox and Internet Explorer
When attempting to print web pages that incorporate background images, users may encounter the issue of these images disappearing upon printing. This article aims to provide solutions for enabling the printing of background images in Firefox and Internet Explorer.
Using a Print Stylesheet
One effective method is to utilize a print stylesheet. This involves creating a separate CSS file for the print version of the page, where the desired print settings can be specified. For example:
/* media:screen */ .star { background: ...; overflow: hidden; text-indent: 9999em; } /* media:print */ .star { text-indent: 0; }
This CSS snippet would display the background image for the ".star" class on the screen, but replace it with an asterisk (*) when printing.
Using Inline Images
Another approach is to use inline images instead of relying on background images. This allows you to specify the visibility of images based on print media:
<div class="star"><img src="./images/star.jpg" alt="*" /></div> /* media:screen */ .star img { visibility: hidden; } /* media:print */ .star img { visibility: visible; }
With this method, the star image will be hidden on screen but visible when printing.
Specifying Print Stylesheets
Finally, to specify which stylesheet should be used for printing, include a "media" attribute in the "" element:
<link rel="stylesheet" type="text/css" href="main.css" media="screen" /> <link rel="print stylesheet" type="text/css" href="print.css" media="print" />
This configuration ensures that "main.css" is used for on-screen viewing, while "print.css" is used for printing. By implementing one of these solutions, users can successfully print background images in Firefox and Internet Explorer.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!