如何在移动浏览器中固定页眉和页脚

时间:2014-03-14 17:50:10

标签: css mobile browser

我正在开发一个与移动浏览器兼容的网站。所以我会设置页眉和页脚固定,这在桌面浏览器上工作正常,但是当我在Android浏览器中打开时,例如页眉滚动和页脚不....这怎么可能? 网站示例为:http://www.mimanchitu.it/prova/

3 个答案:

答案 0 :(得分:0)

你能做到的一种方法是用Jquery或Javascript。 您需要计算屏幕的高度,然后计算页眉和页脚的高度,在您退出所有内容后,您将获得内容的高度。

这样的事情:

var screenHeight=$(window).height();
var headerHeight=$("#idHeade").height();
var footerHeight=$("#idFooter").height();
var total=screenHeight-headerHeight-footerHeight;

$("#content").css("height",total);

然后你把内容变成了一个scrool,就是这样。我将它用于带有phonegap的应用程序,并且运行完美。

答案 1 :(得分:0)

这是CSS

#header, #footer {
    width: 100%;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    box-sizing: border-box;
    z-index: 99;
    position: fixed;
}

答案 2 :(得分:0)

试试这个:

document.getElementById("footer").style.position = "fixed";

为我工作!