Home Web Front-end JS Tutorial Use jquery CSS to control printing style_jquery

Use jquery CSS to control printing style_jquery

May 16, 2016 pm 04:22 PM
css 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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

See all articles