CSS页眉 - 如何使用打印边距? [英] CSS page headers - how to use print margins?

查看:1151
本文介绍了CSS页眉 - 如何使用打印边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在每个网页上打印一个标题,但我是新打印边距。我认为@page css会工作,但它似乎并不影响页面边距。如果我在主体上设置边距,它在第一页上起作用,但后续页面默认情况下会启动顶部边距,将标题放在文本顶部。

I can get a header to print on each page, but I'm new to print margins. I thought the @page css would work, but it does not seem to affect page margins. If I set the margins on the body, it works on page one, but subsequent pages start the top margin at the default, putting the header over top of the text.

<style>  
.header {  
 position: fixed;  
 top: 0;  
}  
@page {  
 size: 11in 17in;  
 margin-left: 1in;  
 margin-right: 1in;  
 margin-top: 1in;  
 margin-bottom: 1in;  
} 
</style>

<body>  
<span class=header>This is the header</span>  
This is the text of the document. (repeat until I get to page 2)  
</body>


推荐答案

所有浏览器的支持支持非常糟糕

Printing support by all browsers is very poorly supported with horrendous bugs in many popular browsers that have gone unfixed for years.

简单的答案是避免HTML / CSS打印,如果你需要确保一个特定的布局。使用PDF,可能动态生成按需。有各种PDF生成器API,如iTextSharp。可以从Flash进行打印,但只有在Flash已安装并正常运行时(即没有Flashblock,iOS)。

The short answer is to avoid HTML/CSS printing if you need to ensure a specific layout. Use PDF, possibly dynamically generated on-demand. There's various PDF generator APIs such as iTextSharp. It's possible to print from Flash, but only if Flash is installed and working (i.e. no Flashblock, iOS).

HTML / CSS打印应限制为简单布局。表格印刷是一种噩梦, fieldset & legend 支持特别有问题(特别是在Firefox上)。有趣的是,打印支持最好是在互联网浏览器上。

HTML/CSS printing should be restricted to simple layouts. Form printing is a nightmare with fieldset & legend support being especially problematic (particularly on Firefox). Interestingly printing support is best on the internet explorers.

CSS3打印支持规范尚未完成,有一些时间了。

The CSS3 printing support specification hasn't been completed and is some time off.

一般原则:


  • 不支援背景或背景CSS图片内部网应用程序的浏览器设置)。

  • No backgrounds or background CSS images are supported (by default - users can change their browser settings for an intranet application). Only foreground images print.

宽度需要随着行星尺寸的变化而变化。美国信件格式比A4版面更短,更宽。

Widths need to be fluid as page sizes vary around the planet. US Letter format is shorter and wider than A4 layout

所有浏览器都支持以不同的方式打印。

All browsers support printing in different ways. Bugs are legion.

使用打印预览进行测试。

Test using print preview.

这篇关于CSS页眉 - 如何使用打印边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆