在IE6中是不能直接使用 position:fixed; 。需要一些 CSS Hack 来解决它。当然,IE6 的问题也不仅仅
position:fixed;
下例让
…
元素固定在浏览器的底部和距离右边的20个像素:
#top{
position:fixed;_position:
absolute;bottom:0;
right:5%;
_bottom:auto;
_top:expression_r(eval_r(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));
}
right 跟 left 属性可以用绝对定位的办法解决,而 top 跟 bottom 就需要用上面的表达式来实现。其中在
_position:absolute; 中的 _ 符号只有 IE6 才能识别,目的是为了区分其他浏览器。
上面的只是一个例子,下面的才是最重要的代码片段:
使元素固定在浏览器的顶部:
#top{
_position:absolute;
_bottom:auto;
_top:expression_r(eval_r(document.documentElement.scrollTop));
}
使元素固定在浏览器的底部:
#top{