一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

ie6浏览器不支持position:fixed解决办法

时间:2013-01-28 编辑:简简单单 来源:一聚教程网

滚动条是body的滚动,固定元素是相对body定位,那么把它设置窗口那么高,不就一直是在窗口那个位置了?

 代码如下 复制代码


html { _overflow: hidden; }
body { _height: 100%; _overflow: auto; }
.box {
    position: fixed;
    left: 10px;
    top: 180px;
    _position: absolute;
}


自家用法介绍

 代码如下 复制代码

html,html body {background-image:url(about:blank);background-attachment:fixed;}/* 修正IE6不支持position:fixed的bug */ 
.bottoms{ width:100%; bottombottom:0; position:fixed;_position:absolute; 
    _bottom:auto; 
    _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0))); 
    } 

推荐淘宝网用的方法

 代码如下 复制代码

*html {/* 只有IE6支持 */
    background-image: url(about:blank); /* 使用空背景 */
    background-attachment: fixed; /* 固定背景 */
}
#box {
    /* 非IE6浏览器使用固定元素 */
    position: fixed;
    top: 0;
    left: 0;
    /* IE6改为绝对定位,并通过css表达式根据滚动位置更改top的值 */
    _position: absolute;
    _top: expression(eval(document.documentElement.scrollTop));
}

热门栏目