`位置:固定'在`< body>`有问题吗? [英] Is `position: fixed` on `<body>` problematic?

查看:180
本文介绍了`位置:固定'在`< body>`有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在移动设备和桌面浏览器的SPA上,我需要在< body> 上设置 position:fixed 以避免iOS溢出/橡皮筋滚动。

On a SPA for mobile devices and desktop browsers I need to set position: fixed on <body> to avoid iOS' overflow/rubberband scrolling.

位置:固定以及对< body>

position: fixed and modifications on the <body> are always somewhat hacky and risky to cause problems.

这就是为什么我想澄清:

This is why I wanted to clarify:

有任何已知问题/注意事项注意(即堆叠上下文,z索引上下文,静态/相对/绝对/固定定位在子项上)/ ...当添加 position:fixed < body>

Are there any known problems / caveats / things to watch out for (i.e. stacking context, z-indexing context, static/relative/absolute/fixed positioning on children) / ... when adding position: fixed to <body>

推荐答案

涉及相对于浏览器窗口定位的元素。网页浏览器缩放受其影响。

The "position: fixed" relates to an "element" positioned relative to the browser window. Webpage browser zooming is affected by it. IE6 and below will also break with it.

也许会更好:

html, body { height: 100%; overflow: auto; }

body .element { position:fixed; bottom: 0; }

然后对于html:

<body>
<div class="element">
    (everything else inside here)
</div>
</body>

这篇关于`位置:固定'在`&lt; body&gt;`有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆