位置:绝对对于浏览器/窗口来说是绝对的

发布于 2024-10-07 02:08:10 字数 415 浏览 1 评论 0原文

据我了解, position:absolute 对于第一个拥有非静态位置的父级来说是绝对的。如果没有父级有指定的位置,那么对于浏览器/窗口来说它将是绝对的。

另一方面,position:fixed 对于浏览器来说是绝对的,但是如果在怪异模式下,它不适用于 IE。

我的问题是我想要一些东西 top:0; left:0; 但网站处于怪异模式,我只在我的个人 div 内编辑。 (这是一个像 myspace 这样的用户网站)。有许多父 div 具有 position:relative

如何让 position:absolute 表现得像 position:fixed 而无需对象静止(如果需要,它可以是静止的)?

It's my understanding that position: absolute is absolute to the first parent who has a non-static position. If no parent has a specified position, then it will be absolute to the browser/window.

position: fixed on the other hand will be absolute to the browser, however it does not work for IE if in quirks mode.

My problem is that I want something to be top:0; left:0; but the website is in quirks mode, and I only edit inside my personal div. (it's a user website like myspace). There are many parent divs that have position: relative.

How can I get position: absolute to act like position: fixed without the need of the object being stationary (it can be stationary if need be)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流云如水 2024-10-14 02:08:10

早期版本的 IE 只是不支持position:fixed;

我唯一知道的是像这样的javacript解决方法:

var layerPadding = 5;
function layerScrollFixEx() {
    if (layerGetScrollPosition() != (document.getElementById('layer').offsetTop - layerPadding)) {
        document.getElementById('layer').style.top = layerGetScrollPosition() + layerPadding + "px";
    }
}

function layerGetScrollPosition() {
    if (typeof window.pageYOffset != 'undefined') {
         return window.pageYOffset;
    }
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
         return document.documentElement.scrollTop;
    }
        else if (typeof document.body != 'undefined') {
         return document.body.scrollTop;
    }
}
layerScrollInterval = window.setInterval("layerScrollFixEx()", 1);

这是我不久前所做的一些代码的代码摘录,当时这仍然相关。

early versions of IE just dont support position: fixed;

the only thing i know of is a javacript workaround like so:

var layerPadding = 5;
function layerScrollFixEx() {
    if (layerGetScrollPosition() != (document.getElementById('layer').offsetTop - layerPadding)) {
        document.getElementById('layer').style.top = layerGetScrollPosition() + layerPadding + "px";
    }
}

function layerGetScrollPosition() {
    if (typeof window.pageYOffset != 'undefined') {
         return window.pageYOffset;
    }
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
         return document.documentElement.scrollTop;
    }
        else if (typeof document.body != 'undefined') {
         return document.body.scrollTop;
    }
}
layerScrollInterval = window.setInterval("layerScrollFixEx()", 1);

this is a code excerpt from some code that i did a while back when this was still relevant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文