网页制作 
首页 > 网页制作 > 浏览文章

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

(编辑:jimmy 日期: 2024/5/20 浏览:3 次 )
效果

提示:您可以先修改部分代码再运行

为了兼容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>

上一篇:CSS解决链接锚点定位偏移的代码
下一篇:css网页布局中文字排版的属性和用法
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网