您的位置:首页 > Web前端 > CSS

css+div fixed属性定位在ie中不兼容的解决办法

2011-05-04 17:36 721 查看
今天调试系统,有个div需要显示在页面的右上角,且随着页面的滚动,一直处在右上角,用了position的fixed属性,但是发现ie不兼容,查找资料后发现主要有四个原因影响:

1,ie不支持fixed

2,可以用absolute代替,但是absolute不会随着页面的滚动改变div的位置,所以必须由js配合

3,用absolute是,必须将left,right,top和bottom四个属性全部设定

4,在js获取页面滚动条当前位置时,有些浏览器用document.documentElement.scrollTop,而有些用document.body.scrollTop,所以在使用时必须做判断

具体代码如下:

.fixedPosition {
 position: fixed;
 top: 3px;
 right: 3px;
 height: 25px;
 width: 150px;
 border: 1px solid black;
 background-color: #f0fff0;
 font-family: arial;
 padding: 0px 10px;
 text-align: center;
 font-size: 12pt;
 font-weight: bold;
 color: black;
 padding-top: 10px;
 cursor: pointer;
}

<!--[if gte IE 5.5]>

<style type="text/css">
.fixedPosition {
  position: absolute;
  right: 3px;
  top: expression( ( 10 + eval( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
  left: auto;
  bottom: auto;
}
</style>

<![endif]-->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  div ie css 浏览器