解决IE6下Position:fixed问题 Position,fixed

在IE6.0及以下版本的浏览器里是不支持position:fixed。而在IE7,IE8,firefox,opera,chrome都可以完美的支持此特性的。

关键词:

解决此问题的要点主要有:

1).容器要有一个背景图片

2).设置它的滚动属性为fixed。

3).用IE特有的e­xpression方法计算出元素的top,left,right,bottom的量。 

<!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>IE6 fixed</title> <style type=”text/css”> * { margin: 0px; padding: 0px; } body { _background-image: url(about:blank); /*用浏览器空白页面作为背景*/ _background-attachment: fixed; /* prevent screen flash in IE6 确保滚动条滚动时,元素不闪动*/ } #topNav { width: 980px; z-index: 100; /*设置浮动层次*/ overflow: visible; position: fixed; top: 50px; /* 其他浏览器下定位,在这里可设置坐标*/ _position: absolute; /*IE6 用absolute模拟fixed*/ _top: expression(documentElement.scrollTop + 50 + “px”); /*IE6 动态设置top位置*/ /* documentElement.scrollTop 设置浮动元素始终在浏览器最顶,可以加一个数值达到排版效果 */ background-color:#0000FF; height: 31px; } .show{ position:absolute; top:500px; left:400px; border:#ff0000 1px solid; } </style> </head> <body> <div class=”jd_menu” id=”topNav”>1111</div> <div style=”height:2000px”></div> <div class=”show”>show</div> <p>  利用给<body>设置固定的背景,防止滚动条滚动时的闪动;如果<body>中要设置滚动的背景而产生冲突,可以把代码写在html选择器里面,如: html { _background-image: url(about:blank); _background-attachment: fixed; /* prevent screen flash in IE6 */ } body { background-image: url(1.jpg); background-attachment: scroll; } </p> </body> </html>

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

解决IE6下Position:fixed问题 Position,fixed

相关文章:

你感兴趣的文章:

标签云: