打印包含绝对元素的所有页面

时间:2014-10-21 15:18:52

标签: html firefox layout printing mozilla

source code

.page{
position:relative;
right:0mm;
height:279mm;
margin:0;
border:1px solid black;
}

*{margin:0;padding:0;}

HTML

<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>

<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>


<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>


<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>


<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>


<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>


<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>


<div class="page">
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`
     </div>
    <div style="position:absolute;top:0px;right:0px ">
      some `DIV` with `position:absolute;top;right`    
    </div>
    <div style="position:absolute;top:0px;right:0px ">
          some `DIV` with `position:absolute;top;right`
    </div>
</div>

页面尺寸为A4纸。

虽然在Firefox中显示所有页面但是 在打印预览中只显示7页的第一页?

在ie和chrome打印预览中是正确的!

此问题是否与Splitting Absolutely positioned frames not implemented - Missing second page of content when printing or print previewing this site有关?

1 个答案:

答案 0 :(得分:1)

你可以这样做,这可能不是正确的答案。它会帮助你朝正确的方向发展

链接

http://www.w3schools.com/css/css_mediatypes.asp

正常使用

.page{
position:relative;
right:0mm;
height:279mm;
margin:0;
border:1px solid black;
}

*{margin:0;padding:0;}

出于打印目的

我们总是创建不同的CSS

仅显示所需内容

您可以使用!important

覆盖css属性
@media only print
{
    body * { display: none !important; }
    body:after { content: "Don't waste paper!"; }
.page{ position:relative!important;; right:0mm; height:279mm; margin:0; border:1px solid black;}
}

set every div in special position with special top and right

很抱歉,你说你不能打印出来。

如果你有一些如何添加,它也会影响其他部分,如页眉,页脚,不一致的表格。

我的建议是制定一个标准的顶部,右侧和位置。这样页面看起来很干净。