防止div尽管位置滚动:绝对 [英] prevent div from scrolling despite position: absolute

查看:50
本文介绍了防止div尽管位置滚动:绝对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临着地狱般的困境".这是html片段:

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>

我了解:

position: absolute;

应该阻止div滚动,但是它仍然可以滚动(尽管刚开始时只有一点点).谁能看到普遍不对的东西?

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:absolute; 设置相对于父坐标的位置,并且在滚动文档时,相对于父级和父级的绝对位置仍为STILL(通过任何级别的计数)相对于整个文档位置

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.

这篇关于防止div尽管位置滚动:绝对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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