手机
当前位置:查字典教程网 >网页设计 > Div+Css教程 >css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法
css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法
摘要:效果fixedie6body{background-image:url(about:blank);background-attachment...

效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>fixed ie6</title><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]--></head><body><div>header</div><div><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>foot</div></body></html>

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

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

<>

HTML:

<body>

<div>

header

</div>

<div>

<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>

foot

</div>

</body>

【css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法】相关文章:

css实现body背景图片水平垂直居中方法

如何处理div+css布局左右浮动问题

10个CSS简写/优化技巧整理

使用css的background:url设置背景图方法

CSS兼容IE6、IE7、IE8和Firefox浏览器的方法

为不同的浏览器载入不同CSS的二种方法

css div绝对定位与固定定位实例

img图片元素下多余空白解决方案

CSS div居中的三种方法

CSS关于解决图片元素下多余空白的BUG

精品推荐
分类导航