IE6、IE7下的z-index问题_html/css_WEB-ITnose
IE6 IE7 z-index 浏览器兼容
有html结构如下:<div class="wrap"> <div class="fl-wrap"> left </div> <div class="fr-wrap"> <ul> <li> <div class="fl"> <div class="pmt-wrap"> <a class="pmt"> 鼠标经过时,显示div </a> <div class="pmt-detail"> ... </div> </div> </div> <div class="fr"> right </div> <div class="clear"></div> </li> <li> <div class="fl"> <div class="pmt-wrap"> <a class="pmt"> 鼠标经过时,显示div </a> <div class="pmt-detail hidden"> ... </div> </div> </div> <div class="fr"> right </div> <div class="clear"></div> </li> </ul> </div> <div class="clear"></div> </div>
登录后复制
相关的css:
.wrap{ border:1px solid red; height:300px; padding:10px; width:500px; } .fl-wrap{ border:1px solid green; float:left; height:100px; width:50px; } .fr-wrap{ border:1px dashed blue; float:right; height:300px; width:440px; } ul{ margin:0; padding:0; } .fr-wrap li{ border:1px solid #000; height:100px; list-style-type:none; margin:5px; padding:5px; } .clear{ clear:both; height:0; overflow:hidden; } .fr-wrap .fl{ border:1px dashed red; float:left; height:100%; width:140px; } .fr-wrap .fr{ border:1px dashed blue; float:right; height:100%; width:260px; } .fl .pmt-wrap{ position:relative; *z-index:2; } .fl .pmt{ cursor:pointer; font-size:12px; margin:5px; padding:0; position:relative; z-index:1; } .fl .pmt-detail{ background-color:#fff; border:1px solid #ccc; height:200px; left:5px; position:absolute; top:16px; width:100px; z-index:3; } .hidden{ display:none; }
登录后复制
火狐下的效果:(也是希望得到的效果)
IE6、IE7下的效果:
已经有按照网络上查到的方法,给.pmt-wrap加上了z-index,但是好像不起作用
回复讨论(解决方案)
<!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=utf-8" /><title>上传图片</title><style type="text/css"> .wrap{ border:1px solid red; height:300px; padding:10px; width:500px; } .fl-wrap{ border:1px solid green; float:left; height:100px; width:50px; } .fr-wrap{ border:1px dashed blue; float:right; height:300px; width:440px; } ul{ margin:0; padding:0; } .fr-wrap li{ border:1px solid #000; height:100px; list-style-type:none; margin:5px; padding:5px; } .clear{ clear:both; height:0; overflow:hidden; } .fr-wrap .fl{ border:1px dashed red; float:left; height:100%; width:140px; } .fr-wrap .fr{ border:1px dashed blue; float:right; height:100%; width:260px; } .fl .pmt-wrap{ position:relative; } .fl .pmt{ cursor:pointer; font-size:12px; margin:5px; padding:0; } .fl .pmt-detail{ background-color:#fff; border:1px solid #ccc; height:200px; left:5px; position:absolute; top:16px; width:100px; z-index:3; display:none; } .hidden{ display:none; }</style><script type="text/javascript">//原生JS写法,,代码比较多,,如果引用JQ库,那就简单多了window.onload=function(){ var oParent = document.getElementById('frWrap'); var oPmt = getByClassName(oParent,'pmt'); //alert(oPmt.length); var pmtDetail = getByClassName(oParent,'pmt-detail'); for(var i= 0; i<oPmt.length; i++){ oPmt[i].index = i; oPmt[i].onmouseover=function(){ //alert(0); //alert(this.index); pmtDetail[this.index].style.display='block'; this.parentNode.style.zIndex='1'; //关键。。给当前父层添加 z-index } oPmt[i].onmouseout=function(){ this.parentNode.style.zIndex=''; pmtDetail[this.index].style.display='none'; } } }// 通过class获取元素function getByClassName(oParent,sClass){ var arrReslut = []; var oEle = oParent.getElementsByTagName('*'); for(var i = 0; i<oEle.length; i++){ if(oEle[i].className==sClass){ arrReslut.push(oEle[i]); } } return arrReslut;}</script></head><body><h2 id="IE-下-需要给父层添加z-index才行-但如果在css加-因为是class-所以后面的也一起添加了-因此需要用JS动态添加到当前的父级-反正你也要实现显示隐藏效果-刚好可以这样实现">IE6下,需要给父层添加z-index才行,但如果在css加,因为是class,所以后面的也一起添加了。因此需要用JS动态添加到当前的父级,反正你也要实现显示隐藏效果,刚好可以这样实现</h2><div class="wrap"> <div class="fl-wrap"> left </div> <div class="fr-wrap" id="frWrap"> <ul> <li> <div class="fl"> <div class="pmt-wrap"> <a class="pmt"> 鼠标经过时,显示div </a> <div class="pmt-detail"> ... </div> </div> </div> <div class="fr"> right </div> <div class="clear"></div> </li> <li> <div class="fl"> <div class="pmt-wrap"> <a class="pmt"> 鼠标经过时,显示div </a> <div class="pmt-detail"> ... </div> </div> </div> <div class="fr"> right </div> <div class="clear"></div> </li> </ul> </div> <div class="clear"></div> </div></body></html>
登录后复制
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
2 周前
By DDD
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前
By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

本文讨论了HTML&lt; Progress&gt;元素,其目的,样式和与&lt; meter&gt;元素。主要重点是使用&lt; progress&gt;为了完成任务和LT;仪表&gt;对于stati

本文讨论了html&lt; datalist&gt;元素,通过提供自动完整建议,改善用户体验并减少错误来增强表格。Character计数:159

本文讨论了HTML&lt; meter&gt;元素,用于在一个范围内显示标量或分数值及其在Web开发中的常见应用。它区分了&lt; meter&gt;从&lt; progress&gt;和前

本文解释了HTML5&lt; time&gt;语义日期/时间表示的元素。 它强调了DateTime属性对机器可读性(ISO 8601格式)的重要性,并在人类可读文本旁边,增强Accessibilit

本文讨论了使用HTML5表单验证属性,例如必需的,图案,最小,最大和长度限制,以直接在浏览器中验证用户输入。

本文讨论了视口元标签,这对于移动设备上的响应式Web设计至关重要。它解释了如何正确使用确保最佳的内容缩放和用户交互,而滥用可能会导致设计和可访问性问题。

本文讨论了&lt; iframe&gt;将外部内容嵌入网页,其常见用途,安全风险以及诸如对象标签和API等替代方案的目的。
