Cleverly use CSS to create printable pages and css to create and print
Creating a printed page with CSS saves some effort without having to create an HTML file for printing. The premise is to use CSS + DIV to layout HTML pages according to "WEB standards.
First, add the CSS file set for the printer to the HTML page.
<link href="css/admin.css" rel="stylesheet" type="text/css" media="screen" /><link href="css/admin-print.css" rel="stylesheet" type="text/css" media="print" />
Media = "screen" is screen-oriented;
Media = "print", which is print-oriented;
2. Create a printed page to remove unnecessary page elements, such as navigation, sidebar, advertisement, and copyright. At this time, we can reflect the advantages of "WEB standards" for page creation. It is easy to change the layout with CSS.
/* Hide the unprinted start */h1 span {/* subtitle */display: none;} # sidebar {/* sidebar */display: none;} # content td. ads {/* Table Ad */display: none;} # content th. col2 span {/* anchor link */display: none;} # content # bottom-2 {/* print table at the end of the page */display: none ;} /* Hide the end of a non-print entry */
Third, print button function, IE, Firefox can be printed normally.
<Input type = button value = "print this page" onclick = "window. print ()">
In addition, there is also a printing page for the local version, which can be "Print Settings" and "print preview", but because of this setting, network printing needs to call a control in IE browser, it also needs to reduce ActiveX control security and can only run on IE, not practical. So just paste the call code and back up.
<OBJECT id = WebBrowser classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 height = 0 width = 0> </OBJECT> <input type = button value = "print preview" onclick = document. all. webBrowser. execWB (7,1)> <input type = button value = "page setting" onclick = document. all. webBrowser. execWB (8, 1)> <input type = button value = "print this page" onclick = document. all. webBrowser. execWB (6, 1)>
Fourth, precautions
In the print style, the print font size is calculated by the point (pt). The font size on the screen is displayed, and pixels (px) are more suitable than dots and feet.
In a print style, the float attribute of CSS may sometimes cause some trouble and cause missing printing pages. Therefore, it is recommended to remove unnecessary block-level display.
I checked some materials about the print settings and customized headers and footers. CSS and HTML cannot be controlled and can only be implemented by calling ActiveX controls, but this is not safe. The best way is to click the browser menu to print the settings before printing.
There is also a tab in CSS that can set pagination characters: "page-break-after" and "page-break-before ". Because there are many forms on my holiday pages, this CSS is not applied. Test the specific effect on your own.