:兼容性好,自动置顶的淘宝悬浮工具栏,DIV绝对置顶(兼容IE,FF) - 李小波

来源:百度文库 编辑:九乡新闻网 时间:2024/05/05 13:44:23
兼容性好,自动置顶的淘宝悬浮工具栏,DIV绝对置顶(兼容IE,FF)

对于IE7,我们可以利用DIV的"position: fixed;"属性。代码如下:

#ie7_ff{
       position: fixed;
       top: 0px;
       left: 0px;
       width: 120px;
}

这段代码对于Firefox浏览器同样适用。但是IE6不支持“position: fixed;”属性。所以针对IE6我们可以用如下代码:

#ie6_ie7{
       position: absolute;
       width: 120px;
       left: 140px;
       top: expression(eval(document.documentElement.scrollTop));
}

这段代码对于IE7同样适用。但是FF不支持。


利用浏览器HACK技巧,我们就可以写出兼容IE6,IE7,FF的CSS代码:

#all_f1{
       width: 150px;
       position: fixed;       //IE7,FF
       _position: absolute;        //IE6
       left: 280px;
       top: 0px;
       _top: expression(eval(document.documentElement.scrollTop));    //IE6
#all_f2{
       width: 150px;
       position: fixed;       //FF
       *position: absolute;        //IE6,IE7
       left: 450px;
       top: 0px;
       *top: expression(eval(document.documentElement.scrollTop));   // IE6,IE7
 

----------------------------------------------------------------------------------------------------




兼容IE6的淘宝悬浮工具栏





ddd