当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法

CSS样式表
CSS中的text-shadow属性
利用CSS3特性和浏览器中的工具进行网页设计
使用CSS3将你的网站设计推向未来
网页设计师福音:CSS网格布局生成器
CSS教程:汇总让IE6崩溃的几种方法
CSS教程:快速提升设计可读性和维护性
HTML5和CSS3给网站设计带来出色效果
CSS选择器大全
TypeSelect实现网页嵌入字体
CSS样式表尽量放到网页头部
CSS3的优势以及网页设计师如何使用CSS3技术
CSS样式表中引用图片地址在各浏览器中的差异
5种给CSS样式表瘦身减肥的方法
英文教程:50个网页制作中应用的CSS技巧
用CSS3将你的设计带入下个高度
CSS教程:新的图像替换方法
创造100%功能自适应css布局的行之有效的方法
轻松搞定IE的CSS制作网页技巧3则
网页设计应该熟知的CSS 3.0技术
制作网页常用的50种CSS工具

CSS样式表 中的 css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 152 ::
收藏到网摘: n/a

效果



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

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