兼容ie6,ie7,ff的fixed,元素上下端固定定位方法

效果地址:点击我

为了兼容ie6(万恶的东西),用的是expression的方法

在页头加入:

<style type="text/css">
body{
	background-image:url(about:blank); background-attachment:fixed;/*必要,防抖动*/
}
.head,.foot{
	position:fixed !important;/*ie7 ff*/
	position:absolute; 
	z-index:21; 
	background:#999;
	height:30px;
	width:500px;
}
.foot{
	bottom:0 !important;/*ie7 ff*/
}
.main{
	height:2000px;
}
</style>
<!--[if IE 6]>
<style type="text/css">
/*ie6 fix顶端元素*/
    .head{
    top:expression(eval(document.documentElement.scrollTop));
}
/*ie6 fix底端元素*/
.foot{
	top: expression(eval((document.compatMode&&document.compatMode=="CSS1Compat")?documentElement.scrollTop+documentElement.clientHeight-this.clientHeight-1:document.body.scrollTop+document.body.clientHeight-this.clientHeight-1));
}
</style>
<![endif]-->

HTML:

<body>
    <div class="head">
    	header
    </div>
    <div class="main">
    	<p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p><p>main </p>
    </div>
    <div class="foot">
    	foot
    </div>
</body>

转载的同学麻烦注明一下出处:http://xiebiji.com/2009/09/fixed

2 Responses to 兼容ie6,ie7,ff的fixed,元素上下端固定... »

  1. 万戈 评论 2009-09-28 14:12

    我是单独为IE6写样式

    回复

    joe 回复 九月 28th, 2009 at 22:34

    :mad: IE6 要早日灭亡

    回复

Leave a Reply

Email address is not published

You should say a Chinese word to pass spam check. If you can not input Chinese, just copy 你好 and paste them into comment text box.