如何声明DIV应显示在每个页面的左上角而不是相对位置。
我有一个像:
<div id=header>Document</div>
我想在左上角的每个页面上使用css显示它:
@page {
size: 8.5in 11in;
margin: 0.25in;
border: thin solid black;
padding: 1em;
@top-left {
content: ???? ;
}
}
谢谢。
答案 0 :(得分:4)
我意识到这个问题有点陈旧,但是对于像我这样来这里寻找方法的人来说,可以使用CSS3运行元素:http://www.w3.org/TR/2007/WD-css3-gcpm-20070504/#running1
在此示例中,除了print之外的所有媒体类型中都隐藏了标题。在打印页面上,标题显示在所有页面的顶部中心,除非显示h1元素。
<style>
div.header { display: none }
@media print {
div.header {
display: block;
position: running(header);
}
@page { @top-center { content: element(header, last-except) }}
</style>
...
<div class="header">Introduction</div>
<h1 class="chapter">An introduction</div>
答案 1 :(得分:0)
不
#header {
position: fixed;
top: 0;
left: 0;
}
工作?见Printing Headers。另外,请查看position: fixed的W3C规范。
编辑:如果我很好地阅读有关Margin Boxes的CSS 3规范,以及有关content
属性的CSS 2.1规范,我认为你不能将页面中的<div>
嵌入到Margin Box的内容中,唉。