CSS+DIV固定底部的漂浮导航条

it2022-05-09  35

经常看到各大网站(例如:天涯,网易,阿里巴巴)的底部会有一个能够固定的漂浮条,该效果可以用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下的缓动问题。

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> <style type="text/css"> body { background-image:url(a.xx); /* for IE6 */ background-attachment:fixed; } #bottomNav { background-color:#096; z-index:999; position:fixed; _position:absolute; /* for IE6 */ width:100%; bottom:0; left:0; _top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */ overflow:visible; } </style> </head> <body> <script> for(var i=0; i<100; i++){ document.writeln("aa<br />"); } </script> <div id="bottomNav">这里加入你的代码固定底部漂浮</div> </body> </html>

  

 

转载于:https://www.cnblogs.com/yuanq_20/articles/3046206.html

相关资源:JS、JQuery、CSS DIV实例大全

最新回复(0)