【发布时间】:2017-04-05 22:34:21
【问题描述】:
大家好,我正面临印刷媒体 css 的问题。 html页面中有两个div,body和footer。
<div class="main-template-body" id="main-template-body">
//content
</div>
<div class="main-template-footer">
//footer
</div>
在打印网页时,我需要将页脚固定在每页的底部。因此,我使用了以下 css 并且效果很好。
.main-template-footer {
display:block;
position:fixed;
bottom:0;
width:100%;
min-height:50px;
height:auto;
}
对于正文部分,我使用了 margin-bottom 来设置页面底部边框的边距,并带有以下 css。为了避免与页脚重叠,但它没有工作。
.main-template-body {
width:100%;
height:auto;
display:block;
position:relative;
//margin-bottom: 20px; tried
//margin-bottom : 2cm; tried it too
}
我的问题是,如何设置'main-template-body' div 和打印页面底部边框之间的边距以避免正文与页脚 div 重叠。
以下 css 将边距设置为正文和页脚。
@page {
margin-bottom: 4cm;//<- How to set this margin to specific div only?
}
提前谢谢各位。
编辑:我更新了下面 2 页的图像,其中首页页脚和内容重叠。内容从第一页继续到第二页。我需要为内容设置边距,这样就不会发生重叠。
【问题讨论】:
-
也许 @media screen, print { div.main-template-body{margin-bottom:4cm;} }
-
@SoniVimal,我试过了,但没有用。不过谢谢。 :)
-
您可以将代码粘贴到 Snippet 中以查看问题吗?
-
当内容大于窗口大小而不是页脚时向下或固定在窗口屏幕中?
-
@Hit,在打印视图中,当内容超过一页时,它会转到另一页。关于页脚,它会在每一页中复制自己并坚持到底,效果很好。我会在帖子中发布图片。