search
HomeWeb Front-endJS TutorialUse jquery CSS to control printing style_jquery

1. Add printing style

1. Prepare a css file for screen display and printing, as shown below:
css for screen display:
css for printing:

2. Import method:

3. Directly write the screen display style and printing style in a css file:
@media print {}{
h1 {
color: black;
}
h2 {}{
color: gray;
}
}
The content in @media print is only valid for the printed content, and the other content is the screen display style.

Others:
It is often useful to create a stylesheet that does not specify a media type (or utilize media="all"). When you're ready to define something special
When it comes to printing rules, you can just create a separate style sheet and disable any styles that don't look good when printed. One problem with using this approach is that you have to make sure that the printer styles actually do override the main style sheet. It's ready to use! important.

2. Notes on printing style:

1. It is not recommended to use background in print styles, because the browser cannot print out the background content in CSS by default. It can only be used when the browser is
The background can be printed only when the background can be set to be printed (optional in the advanced options of IE). Even if the background prints, it may overwhelm any text overlaid on it.
This is true, especially for text that contrasts strongly on a monitor with a colored background, but blends into this background when printed on a black and white printer.
background:none; remove background
Pictures and colors.

You can use the background-color attribute to set the background color to white, like this: font-family: Arial; line-height: 26px;"> You can also get the same effect by using the background shortcut: background: white. Therefore Like background: white;
Such a statement not only sets the background color to white, but also eliminates all background images. Use the shortcut attribute of this background,
You achieve two things - set a white background and eliminate the image - with very little code.

2. If you need pictures to appear in the printed content, please add them in the HTML code.

3. Print settings use physical units, so it is best not to use pixels (px) for size. You can use pt or cm;

4. Hide unnecessary or secondary content. display: none;

5. Try not to let the content float. Some browsers will cause trouble when printing floating divs, which requires special attention.
Don't use floating blocks in printed stylesheets, like this: float: none;. For example, Gecko-based browser
(such as Netscape 6), when the user uses it to browse a printout page, it will truncate the content in the floating element.
The content will not be sent to the printer, and there will be no trace of it on the next page - it will disappear.

6. Try your best to prioritize the important content in the HTML code, which can save a lot of trouble in the printing style.

7. Printing is different from web pages. When printing, white margins must be left, and the unit is inches (in).

8. To ensure that all text on the page prints in black, use a wildcard selector (see page 54) and !important to create a variable that separates each
Tags are all formatted with a single style of black text:
*{ color: ##000# !important }

9. Display link URL information in printing: use an advanced selector: after and an advanced CSS property called content,
Print text that is not displayed on the screen at the end of a style element.
Unfortunately, the :after selector and content attribute tricks don’t work on Internet Explorer 6 or earlier
(As of this writing, it doesn't work on IE 7 either). But it does work on Firefox and Safari, so you at least have the clarity
Describe the URL so that visitors can use their browser.

To do this, add a style to the print stylesheet that prints the URL after each link. You can even add additional text items
Use parentheses to make it look better:
a:after {content: " (" attr(href) ") ";}

However, this CSS does not differentiate between external or internal links, so it also prints useless relative
to other pages on the same website. Document link: "Visit homepage (../../index.html)." With a little CSS 3 magic, you can force this style to only type
Print absolute URLs (i.e. those starting with http://), like this:
a[href^="http://"]:after {content: " (" attr(href) ") ";}

10. Add page breaks to printing: Two widely recognized attributes are page-break-before and page-break-after.
page-break-before tells the web browser to insert a page break before a specified style. Use page-break-before
The property causes the image to be printed on a new page and fit on the entire page.
To make an element appear as the last item on the printed page, add page-break-after: always to that element's style.

Create two class styles, named like .break_after and .break_before, like this:
.break_before { page-break-before: always; }
.break_after { page-break-after: always; }

You can then selectively apply these styles to elements that should print at the top or bottom of the page.

3. Test printing style

Normally speaking, it is impossible for us to use a printer for testing. There is a "Print Preview" in the "File" menu bar of the IE browser, which can be used
Print preview to test.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js Streams with TypeScriptNode.js Streams with TypeScriptApr 30, 2025 am 08:22 AM

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

Python vs. JavaScript: Performance and Efficiency ConsiderationsPython vs. JavaScript: Performance and Efficiency ConsiderationsApr 30, 2025 am 12:08 AM

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

The Origins of JavaScript: Exploring Its Implementation LanguageThe Origins of JavaScript: Exploring Its Implementation LanguageApr 29, 2025 am 12:51 AM

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment