`位置:固定'在`< body>`有问题吗? [英] Is `position: fixed` on `<body>` problematic?
问题描述
在移动设备和桌面浏览器的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> $ c $总是有点黑客和冒险导致问题。
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>
这篇关于`位置:固定'在`< body>`有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!