功能测试
首页 > 设计运营 > 正文

两种解决IE6不支持固定定位的方法

发布-chongzi | 查看- | 发表时间-2009-10-29

有两种让IE6支持position:fixed

1.用CSS执行表达式

*{margin:0;padding:0;}
* html,* html body{
background-image:url(about:blank);
background-attachment:fixed;
}
* html .fixed{
position:absolute;
bottom:auto;
top:eval(document.documentElement.scrollTop+
document.documentElement.clientHeight-this.offsetHeight-
(parseInt(this.currentStyle.marginTop,10)||0)-
(parseInt(this.currentStyle.marginBottom,10)||0)));
}
.fixed{
position:fixed;
bottom:0px;
top:auto;
}

 

2.让body保持其原有高度,让html只有一个窗口那么高


*{margin:0;padding:0}
*html{overflow:hidden;}
*html body{height:100%;overflow:auto;}
.fixed{
position:fixed; _position:absolute;
left:0;
bottom:0;
}

 

第二种方法有个缺点 就是页面内容高度超出浏览器一屏的话 就被隐藏 。建议在 内容为浏览器一屏内使用

3.纯CSS解决方案

<title>纯css方案</title>
<style type="text/css">
*
{
 margin:0;
 padding:0;
}
html, body
{
 height:100%;
 overflow:hidden
}
.body
{
 height:100%;
 overflow:auto;
}
.fixed_box
{
 width:100%;
 height:100px;
 position:absolute; 
 bottom:0;
 z-index:1000;
 border:1px solid black;
 background:#eee;
 line-height:100px;
 text-align:center;
}
</style>
</head>
<body>
<div class="fixed_box">嗯嗯 就是我被固定了</div>
<div class="body">
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
  <p>内容很多 很长</p>
</div>
 

或许你还对下面的文章感兴趣

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近评论
访客留言
QQ11682884
POWER BY 博百优