Is `position: fixed` on `<body>` problematic?

烂漫一生 提交于 2019-12-24 16:29:15

问题


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

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

This is why I wanted to clarify:

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>


回答1:


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.

Perhaps it would be better as:

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

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

Then for the html:

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


来源:https://stackoverflow.com/questions/37584726/is-position-fixed-on-body-problematic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!