internet-explorer - 位置 : absolute to be absolute to the browser/window

标签 internet-explorer quirks-mode css

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

position: fixed 另一方面对于浏览器来说是绝对的,但是如果处于 quirks 模式,它对 IE 不起作用。

我的问题是我希望某些东西成为 top:0; left:0; 但该网站处于怪癖模式,我只在我的个人 div 中进行编辑。 (它是像 myspace 这样的用户网站)。有许多具有 position: relative 的父 div。

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

最佳答案

早期版本的 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);

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

关于internet-explorer - 位置 : absolute to be absolute to the browser/window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4421358/

相关文章:

html - 为什么不溢出 :hidden working in IE6?

html - 为什么我的页面在标准模式下会严重中断?

html - 使图像链接适合容器 div 并将其中的文本居中

php - 如何在导航栏 CSS 和 HTML 上方显示图像

css - 如何使用 CSS 将表格外的文本左对齐

javascript - 根据 IE 窗口大小调整图像大小

javascript - 使用全局 JavaScript 变量和 Internet Explorer 的 YepNope/Modernizr 回调

html - 如何将滚动条放在固定宽度的 div 上,里面有一个表格,它在 HTML 中动态添加固定宽度的 td

html - 在 HTML 和 CSS 中实现完全对齐 : works in limited-quirks mode but no-quirks mode messes up the height

css - 变换旋转在 Quirks 模式下不起作用