简体   繁体   English

如何使用CSS或JavaScript / jQuery在每个页面上打印标题

[英]How do I print a header on every page using CSS or JavaScript/jQuery

I have a page where there is a lot of text, probably 15 pages, I wan't to be able to add a header at the begining of every page when the user prints the document. 我的页面上有很多文本,可能有15页,当用户打印文档时,我将无法在每页的开头添加页眉。

Is this possible with CSS or JavaScript/jQuery???? CSS或JavaScript / jQuery是否可行????

You can use classic CSS by targeting media using media attribute. 您可以通过使用media属性定位媒体来使用经典CSS。

Example: 例:

<link rel="stylesheet" type="text/css" media="all" href="all.css" />
<link rel="stylesheet" type="text/css" media="print" href="print.css" />

Add your <header></header> in your page, position it with CSS, if you don't want it to be included in a browser do: 如果您不希望将<header></header>包含在浏览器中,请使用CSS进行定位:

header {
  display: none;
}

in your all.css 在你的all.css

And in your print.css : 并在您的print.css

header {
  display: block;
}

Print layouts change depending on the browser, default fonts installed, and any other custom settings used. 打印布局根据浏览器,安装的默认字体以及使用的任何其他自定义设置而变化。 How would you know where the page divisions are? 您怎么知道页面划分在哪里?

Your best bet may be to produce a PDF of your documentation. 最好的选择是生成文档的PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM