Use CSS to create a print page. You don't have to create an HTML file specifically for printing, which can save some energy. The premise is to use CSS+p to layout the HTML page according to the "WEB standard".
First, add the CSS file set for the printer to the HTML page
<link> <link>
media="screen" is screen-oriented;
media="print" is for printing;
Second, create a print version of the page and remove unnecessary page elements, such as navigation, sidebars, advertisements, copyrights, etc. At this time, the advantage of making pages according to "WEB standards" can be reflected. It is easy to change the layout with CSS.
/* 隐藏不打印项 start */ h1 span { /* 副标题 */ display: none; } #sidebar { /* 侧栏 */ display: none; } #content td.ads { /* 表格内广告 */ display: none; } #content th.col2 span { /* 锚链接 */ display: none; } #content #bottom-2 { /* 页尾表格打印 */ display: none; } /* 隐藏不打印项 end */
Third, the print button function can print normally in IE and Firefox.
<input>
In addition, there is a local version of the printing page that allows for "print settings" and "print preview". However, because of this setting, network printing needs to call a control in the IE browser, and the security of the ActiveX control needs to be reduced, and it can only be used in IE. Running on it is not practical. So I only post the calling code for backup.
<input> <input> <input>
Fourth, things to note
In print styles, print font size is measured in points (pt), and for on-screen font size display, pixels (px) are more appropriate than points and feet.
In print styles, the float attribute of CSS may sometimes cause some trouble and cause the printed page to be missing, so try to remove unnecessary block-level display.
Regarding print settings and customizing headers and footers, I checked some information and found that CSS and HTML cannot be controlled and can only be achieved by calling ActiveX controls, but this is not safe. The best way is to click on the browser menu to set the print settings yourself before printing.
There is also a tag in CSS that can set page breaks: "page-break-after" and "page-break-before". Because my holiday page has many tables, I didn’t apply this CSS. You can test the specific effect yourself.
The above is the detailed content of Teach you how to create a print page with CSS. For more information, please follow other related articles on the PHP Chinese website!

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more.

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!
