我面临着一个'div hell'。 这是html片段:
<div id="xyz" class="sensoricon moveable type1 node-2-sensor-1 string1" style="position: absolute; top: 241.467px; left: 236.417px; opacity: 1;"> <img src="/content/images/shared/sensors/bla.png" alt=""> </div>我明白那个:
position: absolute;应该防止div滚动,但它仍然会(尽管开头只有一点点)。 任何人都可以看到一般错误吗?
I am facing a bit of a 'div hell'. This is the html snippet:
<div id="xyz" class="sensoricon moveable type1 node-2-sensor-1 string1" style="position: absolute; top: 241.467px; left: 236.417px; opacity: 1;"> <img src="/content/images/shared/sensors/bla.png" alt=""> </div>I understand that:
position: absolute;should prevent the div from scrolling, but it still does (although only a little bit at the beginning). Can anyone see anything generally wrong?
最满意答案
你想要做的是:
position: fixed;因为位置:绝对; 设置相对于父坐标的位置,当滚动文档时,绝对位置相对于父级和父级(通过任何级别计数)仍相对于整个文档位置。
另一方面, position:fixed设置相对于windows而不是document的位置,这样滚动时它就会停留在同一个地方。
What you want to do is:
position: fixed;Because position: absolute; sets position relative to parent coordinates and when the document is scrolled, absolute position is STILL relative to parent's and parents (through whatever count of levels) is relative to whole document position.
On the other hand position: fixed sets position relative to window's and not document's. That way your element stays in the same place when scrolled.
更多推荐
发布评论