当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > ie6 fixed bug的解决方法 (css+js)

CSS样式表
css ID类和class类的长命名与短命名
CSS background-position的使用说明详解
利用CSS定位背景图片 background-position
CSS 多图片融合背景定位的应用于优缺点分析
CSS实现的图片宽高自适应固定边框
css 背景图片定位在菜单效果中的应用实例
CSS 速记口诀 可以解决一些常见问题
CSS 多浏览器兼容性问题及解决方案
css 行级元素在多浏览器下的宽度问题 与解决方法
IE下行框高度的问题
CSS 实现的图片宽高自适应固定边框
css的核心内容 标准流、盒子模型、浮动、定位等分析
CSS 超出隐藏实现限制字数的功能代码(多浏览器)
Div+CSS 布局入门教程之二 构建网站
CSS 网页布局中文排版的9则技巧
CSS网页布局25个实用小技巧
网页制作 默认Web字体样式
IE与Firefox的CSS兼容大全 推荐
css 非表格垂直对齐效果代码
css cursor 的可选值(鼠标的各种样式)

CSS样式表 中的 ie6 fixed bug的解决方法 (css+js)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-20   浏览: 221 ::
收藏到网摘: n/a


复制代码
代码如下:

#fixed {
position: absolute;
top: 0;
left: 0;
width: 10em;
height: 100%;
}
body > #fixed {
position: fixed;
}
#content {
margin-left: 10em;
background:red;
height:800px;
}

利用css选择器覆盖原position的属性值;
fixed层的父层需是body才能这样实现;
但是这样还不完美 并不能完全实现效果,因为不会随body页面拉动而滚动
要实现随body页面滚动而滚动 需添加以下js代码

复制代码
代码如下:

<script language="javascript" type="text/javascript">
function fixedPop1(){
var m=60; //top值
var obj=document.getElementById("TopDivInner"); //position:fixed对象
var n=50; //top值
var obj2=document.getElementById("TopDiv"); //position:fixed对象
window.onscroll=function(){obj2.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';
obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+m+'px';
}
window.onresize=function(){obj2.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';
obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+m+'px';
}
};
$(function(){
fixedPop1();
});
</script>

豆瓣的弹出登陆框就是利用这样的方式实现的,当然要在js代码上加 if IE6的
到此,加上通过js判断屏幕分辨率进而改变弹出框的位置,使其更加合理化,就基本完成了豆瓣弹出登陆款的实现
 
然而这个在ie6下存在拖动滚动条引起登陆框闪动的问题,为解决这个问题可以利用css e xpression 代价是更高的内存占用

复制代码
代码如下:

<!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>无标题文档</title>
<style type="text/css">
*
{
margin: 0px;
padding: 0px;
}
body {
background-image: url(http://global.tianya.cn/global/gnav/css/nothing.txt);
background-attachment: fixed; /* prevent screen flash in IE6 */
}
#topNavWrapper {
width: 980px;
text-align: left;
height: 31px;
margin: 0px auto;
z-index:100;
_position: relative ;
_top:0px;
}
#topNav {
width: 980px;
float: left;
display: block;
z-index: 100;
overflow: visible;
position: fixed;
top: 0px; /* position fixed for IE6 */
_position: absolute;
_top: e­xpression(documentElement.scrollTop + "px");
background-image: url(http://global.tianya.cn/global/gnav/images/top_r.gif);
background-repeat: no-repeat;
background-position: right;
height: 31px;
}
.show{
position:absolute;
top:500px;
left:400px;
border:#ff0000 1px solid;
}
</style>
</head>
<body>
<div id="topNavWrapper">
<ul class="jd_menu" id="topNav">
</ul>
</div>
这里是大量的br换行标签。
<div class="show">show</div>
</body>
</html>

since1984应该利用类似的技术实现其底部半透明框框