jQuery Mobile:将页脚粘贴到页面底部

Ser*_*gio 70 css jquery-mobile

有没有办法,记住jQuery Mobile框架的运作方式,修复页面,使页脚始终与页面底部对齐 - 无论高度如何.

因为它会改变jQuery页面的高度,特别是当设备从纵向旋转到横向时,所以解决方案必须考虑到这一点.

只是为了澄清 - 我不需要页脚位于视口的底部,只是工作,以便默认页面高度不会低于视口高度.

谢谢.

Phi*_*lip 113

您可以在css文件中添加:

[data-role=page]{height: 100% !important; position:relative !important;}
[data-role=footer]{bottom:0; position:absolute !important; top: auto !important; width:100%;}  
Run Code Online (Sandbox Code Playgroud)

因此页面数据角色现在具有100%的高度,并且页脚处于绝对位置.

此外,Yappo写了一个很棒的插件,你可以在这里找到:iScroll插件中的jQuery Mobile http://yappo.github.com/projects/jquery.mobile.iscroll/livedemo.html

希望你找到答案!

答案更新

您现在可以使用该data-position="fixed"属性将页脚元素保留在底部.
文档和演示:http://view.jquerymobile.com/master/demos/toolbar-fixed/

  • 这解决了PC尺寸显示器的问题.然而,在手机上,现在页脚大约在页面的一半处.因此,我不认为这个解决方案有效.但是,我确实喜欢仅CSS的方法. (5认同)
  • 我更喜欢位置:固定为一个我希望始终在底部可用的页脚. (2认同)

Nic*_*son 60

由于这个问题有点陈旧,很多事情都发生了变化.

您现在可以通过将此添加到页脚div来获得此行为

data-position="fixed"
Run Code Online (Sandbox Code Playgroud)

更多信息:http: //jquerymobile.com/test/docs/toolbars/bars-fixed.html

另外要注意,如果您将前面提到的CSS与新的JQM解决方案一起使用,您将无法获得相应的行为!

  • 关于这个问题唯一令人烦恼的部分是,它似乎总是漂浮在你的内容之上,而不是只是在没有足够的内容来填补空白时走到最底层. (3认同)
  • 应使用jquerymobile 1.7+将其标记为正确答案 (2认同)

joc*_*ull 15

在我的情况下,我需要使用这样的东西,如果没有太多内容,将页脚固定在底部,但不要像data-position="fixed"往常一样漂浮在所有内容之上......

.ui-content
{
    margin-bottom:75px; /* Set this to whatever your footer size is... */
}

.ui-footer {
    position: absolute !important;
    bottom: 0;
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)


Ped*_*ito 5

修正了基础知识

若要在页眉或页脚上启用此行为,请将该data-position="fixed"属性添加 到jQuery Mobile页眉或页脚元素.

<div data-role="footer" data-position="fixed">
    <h1>Fixed Footer!</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

  • 这应该是答案 (2认同)