经常看到各大网站(例如:天涯,网易,阿里巴巴)的底部会有一个能够固定的漂浮条,该效果可以用js实现,但是今天新鲜代码站推荐一个纯css方法,更加简洁方便。

 

css代码如下:

body { background-p_w_picpath:url(text.txt); /* for IE6 */ 
background-p_w_upload: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-p_w_picpath:url(text.txt);
注意这里的 text.txt 其实不需要有这个txt文档,txt的文件名叫什么看自己喜好喽,如此一来我们就解决了IE6下的缓动问题。


PS:你可能会对 text.txt 和 expression 感到郁闷,也有人使用多嵌套一层 DIV 做了个假滚动条实现了这个方法,当然这种方法在也会相应的改动下默认属性,可这种写法和之前网站融合起来很郁闷,要添加一个DIV(因为我之前没有在最外层写DIV.wrap)。

 

 

 
  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3.  
  4. <head> 
  5. <style type="text/css"> 
  6. body {  
  7.     background-p_w_picpath:url(a.xx); /* for IE6 */  
  8.     background-p_w_upload:fixed;  
  9. #bottomNav {  
  10.     background-color:#096;  
  11.     z-index:999;  
  12.     position:fixed;  
  13.     _position:absolute; /* for IE6 */ 
  14.     width:100%;  
  15.      
  16.     bottom:0;  
  17.     left:0;  
  18.     _top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */  
  19.     overflow:visible;  
  20. </style> 
  21. </head> 
  22.  
  23. <body> 
  24. <script> 
  25. for(var i=0; i<100; i++){ 
  26.     document.writeln("aa<br />"); 
  27. </script> 
  28.  
  29. <div id="bottomNav">这里加入你的代码固定底部漂浮</div> 
  30. </body> 
  31. </html>