Anu*_*tel 11 html javascript css internet-explorer
我被要求在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");
Run Code Online (Sandbox Code Playgroud)
我尝试使用表格,适用于所有页面,除了最后一页.
我尝试了其他一些保证金和这样的调整,但他们也没有工作.
我实际上希望页脚只显示在打印输出的最后一页的底部,如果可能的话.
Anu*_*tel 12
如果其他人需要解决方案,我正在回答我自己的问题.
经过长时间的研究和密集尝试(主要是试验和错误),我使用以下逻辑将页脚设置在最后一页的底部: -
在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>
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
jQuery的:
@('#whiteBg').height( $('#content')).height() );
Run Code Online (Sandbox Code Playgroud)
为了获得每页底部的乐趣,我使用了:(第二场景)
CSS:
@media print {
#footer {
position: fixed;
bottom: 0;
}
body {
margin: x x y x; (y should reflect the height of the footer);
}
Run Code Online (Sandbox Code Playgroud)