IE 6与位置:固定

Cud*_*dos 7 css position fixed internet-explorer-6

位置:已修复,不适用于Internet Explorer 6.我无法理解谷歌上发现的修复程序.我需要它在IE6,IE7,IE8和FireFox 3.0中工作.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
    <title>Sidebar fixed</title>
    <style type="text/css">
    #wrapper {
        position:relative;
        width:900px;
        margin:0 auto 0 auto;
    }
    #sidebar_left {
        position:fixed;
        height:200px;
        width:200px;
        border:1px solid #000;
    }
    #sidebar_right {
        position:fixed;
        height:200px;
        width:200px;
        margin-left:700px;
        border:1px solid #000;
    }
    #content {
        position:absolute;
        height:2000px;
        width:480px;
        margin-left:210px;
        border:1px solid #000;
    }
    </style>
</head>
<body>
    <div id="wrapper">
        <div id="sidebar_left">
            <p>Left sidebar</p>
        </div>
        <div id="sidebar_right">
            <p>Right sidebar</p>
        </div>
        <div id="content">
            <p>This is the content</p>
        </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Mat*_*hew 20

不支持IE6!人们越早停止攻击IE6的网站,它的牵引力就越小,死亡的速度就越快!或者,在第一个样式块之后添加此代码;

<!--[if IE 6]>  
<style type="text/css">  
#sidebar_right, #sidebar_left {  
position:absolute; /* position fixed for IE6 */  
top:expression(0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px');  
left:expression(0+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px');  
}  
</style>  
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

结果不是超级平滑,但确实有效.

UPDATE

我不太清楚如何使用它; 只需将具有"position:fixed"的任何元素的id(或类)添加到上述块开头的声明列表中,它们将在IE6中表现自己.

  • "不支持IE6"很容易说(我经常说),但有时你只是没有选择. (9认同)

小智 5

是的IE6糟透了.这是黑客......

_position: absolute;
_top: expression(0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px');
Run Code Online (Sandbox Code Playgroud)

这基本上告诉IE6,即使它滚动,它也绝对位于左上角.这应该在你的css的其余部分下面的元素,所以它在IE6中超越它.

这是你的左栏...

#leftBar {
position:fixed;
top:0;
left:0;
width:200px;
_position:absolute;
_top:expression(0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px');
}
Run Code Online (Sandbox Code Playgroud)