当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > CSS教程:兼容ie6,ie7,ff的fixed

CSS样式表
CSS3教程(10):CSS3 HSL声明设置颜色
CSS3教程:新增加的结构伪类
网页布局绝对定位(position)轻松简单
掌握盒模型轻松DIV CSS网页布局
实例方式学CSS text-align怎么用
网页重构时在IE6中遇到png兼容性
CSS3教程:边框属性border的极致应用
CSS网页布局使用表格可以吗?
最新版本的CSS选择器浏览器支持情况
有序列表和段落设计华丽的网页列表数字
CSS教程:通过实例学习和理解CSS盒模型
CSS网页布局的核心内容:CSS盒模型
CSS3伪类选择器:nth-child()
CSS教程:inline-block在各浏览器的显示
CSS实现网页分栏布局的方法:绝对定位和浮动
CSS实例:用CSS制作网页像素画
CSS教程:三列固定网页布局实例
无hack无js全兼容text-overflow-ellipsis效果
CSS解决方案:IE6中遇到png兼容性
CSS学习之类目之间竖线的练习实例

CSS样式表 中的 CSS教程:兼容ie6,ie7,ff的fixed


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

效果地址:


[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

出处:http://xiebiji.com/2009/09/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>