Table of Contents
Styles designed for printers rather than screens
  链接的处理
  控制打印设置选项
  @PAGE规则纸张大小设置
 PAGE ModelThe Page Model
 PAGE Margin ModelPage-Margin Boxes
Home Web Front-end HTML Tutorial CSS styles designed specifically for controlling printing_html/css_WEB-ITnose

CSS styles designed specifically for controlling printing_html/css_WEB-ITnose

Jun 24, 2016 am 11:46 AM

Most web designers are not very familiar with print controls and are often more obsessed with pixels than printers. In the real world, many people rely on printing web pages from websites for reference: In this digital age, many people still have paper in their hands on some special occasions. There are some things web developers can do to bridge the gap between printers and LCD screens.

Styles designed for printers rather than screens

1

2

3

4

5

/* Style will only be applied to print*/

@media print {

}

Note* You can also specify this style specifically for printing by setting the media="print" attribute of the link in a separate CSS file

1

It is not necessary to reshape the entire CSS for your site; overall, the default style is inherited from print; only limited to different needs. To save toner when printing, most browsers automatically invert colors. For best results, the color change should be obvious:

1

2

3

4

5

6

7

/*black and white*/

@media print {

body {

color: #000;

background: #fff; We are not creating screenshots of the entire web page, just to show a well-designed, readable website:

1

2 3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

/*Remove background image, save pen black*/

h1 {

color: #fff;

background: url(banner.jpg);

}

@media print {

h1 {

color: #000;

background: none;

}

nav, aside {

display: none; The printer is more efficient and should only display the main content and remove the header and footer navigation bar

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

@media print {

    h1 {

       color: #000;

       background: none;

    }

 

 

    nav, aside {

       display: none;

    }

 

 

    body, article {

       width: 100%;

       margin: 0;

       padding: 0;

    }

 

 

    @page {

       margin: 2cm;

    }

}

  链接的处理

  在打印机上链接是看不到的,应对超链接进行扩展

1

2

3

4

5

6

7

8

9

10

11

12

/*在超链接后面添加带< http://XXX>的完整地址*/

@media print {

    article a {

       font-weight: bolder;

       text-decoration: none;

    }

 

 

    article a[href^=http]:after {

       content:" <" attr(href) "> ";

    }

}

  显示效果可能是这样的

  控制打印设置选项

  该@page规则允许您指定页面的各个方面。例如,你将要指定页面的尺寸。页边 距,页眉页脚等都是非常重要的。[很多浏览器均己支持]

  @PAGE规则纸张大小设置

  通过下面这条CSS您可以设置纸张大小,5.5英寸宽,8.5英寸高.

1

2

3

@page {

   size: 5.5in 8.5in;

}

  你还可以通过别名控制纸张大小,如"A4"或“legal.”

1

2

3

@page {

size: A4;

}

You still have You can control the printing direction, portrait: portrait printing, landscape: landscape: landscape

1

2

3

@page {

size: A4 landscape;

}

 PAGE ModelThe Page Model

 In paginated media In the formatting model, documents are moved into one or more page boxes. The page frame is mapped to a rectangular plane. This is roughly similar to the CSS box model.

 Note*: Supports fewer browsers

1

@page { width: 50em; }

 PAGE Margin ModelPage-Margin Boxes

Before going any further, we should understand the box model of the page because it behaves with how it works on the screen The job is a little different.

The page model defines the page area and then divides it into 16 peripheral edge boxes. You can control the size of the page area and the size of the margin between the edge of the page area and the end of the page itself.

Left and right margins

1

2

3

4

5

6

7

8

@page :left {

margin- left: 30cm;

}

@page :right {

margin-left: 4cm;

}

The following css will display the title at the bottom left, the page counter at the bottom right, and the chapter title at the top right.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

@page:right{

@bottom-left {

margin: 10pt 0 30pt 0;

border-top: .25pt solid #666;

content: "Our Cats";

font-size: 9pt;

color: #333;

}

@bottom-right {

margin: 10pt 0 30pt 0;

border-top: .25pt solid #666;

content: counter(page);

font -size: 9pt;

}

@top-right {

content: string(doctitle);

margin: 30pt 0 10pt 0;

font-size: 9pt;

color: #333;

}

}

The display effect is as follows:

Note* This article is compiled from: Tips And Tricks For Print Style Sheets and Designing For Print With CSS and css3 page specifications

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)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

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.

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.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles