经常看到各大网站(例如:天涯,网易,阿里巴巴)的底部会有一个能够固定的漂浮条,该效果可以用js实现,但是今天新鲜代码站推荐一个纯css方法,更加简洁方便。
css代码如下:
body { background-image:url(text.txt); /* for IE6 */
background-attachment:fixed; }
#bottomNav { background-color:#096; z-index:999; position:fixed; bottom:0; left:0; width:100%; _position:absolute; /* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */ overflow:visible; }
html代码如下:
<div id="bottomNav">这里加入你的代码固定底部漂浮</div>
再看看这些需要注意的地方:
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight);
看到 _top 是为IE6独家准备的,但是当我只加了上面这句时,IE6下拉动滚动条看到的这个漂浮物是抖动的-_-||| 解决方法我们为IE6添加这样一条语句:
background-image:url(text.txt);
注意这里的 text.txt 其实不需要有这个txt文档,txt的文件名叫什么看自己喜好喽,如此一来我们就解决了IE6下的缓动问题。
看到 _top 是为IE6独家准备的,但是当我只加了上面这句时,IE6下拉动滚动条看到的这个漂浮物是抖动的-_-||| 解决方法我们为IE6添加这样一条语句:
background-image:url(text.txt);
注意这里的 text.txt 其实不需要有这个txt文档,txt的文件名叫什么看自己喜好喽,如此一来我们就解决了IE6下的缓动问题。
PS:你可能会对 text.txt 和 expression 感到郁闷,也有人使用多嵌套一层 DIV 做了个假滚动条实现了这个方法,当然这种方法在也会相应的改动下默认属性,可这种写法和之前网站融合起来很郁闷,要添加一个DIV(因为我之前没有在最外层写DIV.wrap)。
<!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=gb2312" />
<title>CSS+DIV固定底部的漂浮导航条(多浏览器兼容)</title>
<style type="text/css">
body { background-image:url(text.txt); /* for IE6 */
background-attachment:fixed; }
#bottomNav { background-color:#096; z-index:999; position:fixed; bottom:0; left:0; width:100%; _position:absolute; /* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */ overflow:visible; }
</style>
</head>
<body>
</p>
<div id="bottomNav">这里加入你的代码固定底部漂浮</div>
<br />
<br />
<br />
<br />111111111111
<br />
<br />
<br />
<br />
<br />11111111111
<br />
<br />
<br />
<br />
<br />
<br />
<br />122222222222
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />222222333333333
<br />
<br />
<br />
<br />
<br />33334444444444444
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />55555555555555555
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />888888888888888888
<br />
<br />
<br />
<br />
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<style type="text/css">
.fixed-top /* 头部固定 */{position:fixed;bottom:auto;top:0px;}
.fixed-bottom /* 底部固定 */{position:fixed;bottom:0px;top:auto;}
.fixed-left /* 左侧固定 */{position:fixed;right:auto;left:0px;}
.fixed-right /* 右侧固定 */{position:fixed;right:0px;left:auto;}
/* 上面的是除了IE6的主流浏览器通用的方法 */
* html,* html body /* 修正IE6振动bug */{background-image:url(about:blank);background-attachment:fixed;}
* html .fixed-top /* IE6 头部固定 */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
* html .fixed-right /* IE6 右侧固定 */ {position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));}
* html .fixed-bottom /* IE6 底部固定 */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}
* html .fixed-left /* IE6 左侧固定 */{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft));}
</style>
</head>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
lkji<br>
<div id="ss" class="fixed-bottom" style="background-color: red;">1111</div>
<body>
</body>
</html>
http://www.xiaoneidaima.com/art_css/20101118/111R332010.html