search
HomeWeb Front-endHTML TutorialIE6、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>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the root tag in an HTML document?What is the root tag in an HTML document?Apr 29, 2025 am 12:10 AM

TheroottaginanHTMLdocumentis.Itservesasthetop-levelelementthatencapsulatesallothercontent,ensuringproperdocumentstructureandbrowserparsing.

Are the HTML tags and elements the same thing?Are the HTML tags and elements the same thing?Apr 28, 2025 pm 05:44 PM

The article explains that HTML tags are syntax markers used to define elements, while elements are complete units including tags and content. They work together to structure webpages.Character count: 159

What is the significance of <head> and <body> tag in HTML?What is the significance of <head> and <body> tag in HTML?Apr 28, 2025 pm 05:43 PM

The article discusses the roles of <head> and <body> tags in HTML, their impact on user experience, and SEO implications. Proper structuring enhances website functionality and search engine optimization.

What is the difference between <strong>, <b> tags and <em>, <i> tags?What is the difference between <strong>, <b> tags and <em>, <i> tags?Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

Please explain how to indicate the character set being used by a document in HTML?Please explain how to indicate the character set being used by a document in HTML?Apr 28, 2025 pm 05:41 PM

Article discusses specifying character encoding in HTML, focusing on UTF-8. Main issue: ensuring correct display of text, preventing garbled characters, and enhancing SEO and accessibility.

What are the various formatting tags in HTML?What are the various formatting tags in HTML?Apr 28, 2025 pm 05:39 PM

The article discusses various HTML formatting tags used for structuring and styling web content, emphasizing their effects on text appearance and the importance of semantic tags for accessibility and SEO.

What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?Apr 28, 2025 pm 05:39 PM

The article discusses the differences between HTML's 'id' and 'class' attributes, focusing on their uniqueness, purpose, CSS syntax, and specificity. It explains how their use impacts webpage styling and functionality, and provides best practices for

What is the 'class' attribute in HTML?What is the 'class' attribute in HTML?Apr 28, 2025 pm 05:37 PM

The article explains the HTML 'class' attribute's role in grouping elements for styling and JavaScript manipulation, contrasting it with the unique 'id' attribute.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),