我被要求在html网页的每个页面底部打印一个页脚(不是浏览器上的实际页面)。你们知道怎么办? (它应该适用于IE,只是IE很好)
我尝试使用固定底部,但内容与页脚重叠。
我尝试使用javascript计算空间并给出一个空div高度:使用if底部页面高度%!= 0,添加必需的差距。但是页脚底部的值和所需的空格似乎随着元素类型的变化而变化。
var printPageHeight = 1900;
var mFooter = $("#footer-nt");
var bottomPos = mFooter.position().top + mFooter.height();
var remainingGap = (bottomPos <printPageHeight ) ? (printPageHeight -bottomPos) : printPageHeight - (bottomPos % printPageHeight );
$("#whiteSpaceToPositionFooter").css("height", remainingGap+"px");
我尝试使用表格,适用于所有页面,除了最后一页。
我尝试了其他一些保证金和这样的调整,但他们也没有工作。
我实际上希望页脚只显示在打印输出的最后一页的底部,如果可能的话。
如果其他人需要解决方案,我正在回答我自己的问题。
经过长时间的研究和密集尝试(主要是试验和错误),我使用以下逻辑将页脚设置在最后一页的底部: -
在css中:@media print {position:fixed;顶部:0;左:0; z-index -1; Ad IE将其显示在每个页面的底部,并通过z-index发送到后台。
尽管如此,IE中的文本背景在打印时仍然是透明的,因此文本位于页脚顶部。因此,在绝对左上角位置使用1px×1px的白色图像作为图像的背景。
使用javaScript设置图像的高度和宽度,与具有内容的div的高度相同。
HTML:
<body>
<div id="wrapper"> <!-- not necessary -->
<img scr="./img/white.png" id="whiteBg" />
<div id="content">
<!-- content here -->
</div>
</div>
<div id="footer">
</div>
</body>
CSS:
@media screen {
#whiteBg {
display: none;
}
}
@media print {
#whiteBg {
display: block;
position: absolute;
top: 0;
left: 0;
z-index: -1; //to send it to the background
}
#wrapper {
padding-bottom: (the size of the footer, to make footer visible on last page).
}
#footer {
position: fixed;
bottom: 0;
}
}
jQuery的:
@('#whiteBg').height( $('#content')).height() );
为了获得每页底部的内容,我使用了:(第二场景)
CSS:
@media print {
#footer {
position: fixed;
bottom: 0;
}
body {
margin: x x y x; (y should reflect the height of the footer);
}
如果其他人需要解决方案,我正在回答我自己的问题。
经过长时间的研究和密集尝试(主要是试验和错误),我使用以下逻辑将页脚设置在最后一页的底部: -
在css中:@media print {position:fixed;顶部:0;左:0; z-index -1; Ad IE将其显示在每个页面的底部,并通过z-index发送到后台。
尽管如此,IE中的文本背景在打印时仍然是透明的,因此文本位于页脚顶部。因此,在绝对左上角位置使用1px×1px的白色图像作为图像的背景。
使用javaScript设置图像的高度和宽度,与具有内容的div的高度相同。
HTML:
<body>
<div id="wrapper"> <!-- not necessary -->
<img scr="./img/white.png" id="whiteBg" />
<div id="content">
<!-- content here -->
</div>
</div>
<div id="footer">
</div>
</body>
CSS:
@media screen {
#whiteBg {
display: none;
}
}
@media print {
#whiteBg {
display: block;
position: absolute;
top: 0;
left: 0;
z-index: -1; //to send it to the background
}
#wrapper {
padding-bottom: (the size of the footer, to make footer visible on last page).
}
#footer {
position: fixed;
bottom: 0;
}
}
jQuery的:
@('#whiteBg').height( $('#content')).height() );
为了获得每页底部的内容,我使用了:(第二场景)
CSS:
@media print {
#footer {
position: fixed;
bottom: 0;
}
body {
margin: x x y x; (y should reflect the height of the footer);
}
也许是这样的?
<link rel="stylesheet" href="print.css" type="text/css" media="print" /> /* this css file is only for printing purposes*/
body:after {
content: "I am the footer";
}
使用文档末尾的最后一个元素而不是正文...