【问题标题】:Is `position: fixed` on `<body>` problematic?`<body>` 上的 `position: fixed` 有问题吗?
【发布时间】:2016-06-02 15:25:14
【问题描述】:

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

position: fixed 和对&lt;body&gt; 的修改总是有点hacky 并且有风险导致问题。

这就是我想澄清的原因:

在添加position: fixed 时,是否有任何已知问题/警告/需要注意的事项(即堆叠上下文、z 索引上下文、静态/相对/绝对/固定儿童定位)/... &lt;body&gt;

【问题讨论】:

  • 我没有听说过。

标签: html css css-position absolute document-body


【解决方案1】:

“位置:固定”与相对于浏览器窗口定位的“元素”有关。网页浏览器缩放会受到它的影响。 IE6及以下也将与它中断。

或许这样会更好:

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

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

那么对于html:

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

【讨论】:

  • 还有人支持
猜你喜欢
  • 1970-01-01
  • 2011-06-16
  • 2012-11-07
  • 2011-08-23
  • 1970-01-01
  • 2014-09-21
  • 1970-01-01
  • 1970-01-01
  • 2011-08-24
相关资源
最近更新 更多