直接上代码:

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

来源jb51

标签: IE6, 解决, Position, fixed

已有 11 条评论

  1. 林肆 林肆

    css hack之类的东西,我是很头痛了,我希望以后能够统一哇。你这个fixed我很少用~

  2. ie10挺不错的

    1. 呵呵 我一般都不用IE的

  3. IE6越来越少人用了

  4. 这么多代码 看不懂的人表示很头晕

  5. 有时候写样式还要考虑能否在IE6正常显示,恨不得IE6马上消失..

  6. 天哪,,太麻烦了,如果我以后的工作要兼容IE6,,我会很想掐死老板的。。

  7. 写的很正确

添加新评论