参考:http://www.cnblogs.com/JustinYoung/archive/<chsdate year="2007" month="7" day="18" islunardate="False" isrocdate="False" w:st="on">2007/07/18</chsdate>/821868.html
首先,我们不得不承认IE7以前的IE系列浏览器对web标准支持的真的很差。IE6的诡异解析模式让一些开始学习web标准的朋友老是碰到不能理解的问题。特别是这个IE6向IE7过渡的是非年代。IE6真的让人很郁闷。但是就目前而言,我们还是不能放弃对IE6的兼容。从下面的我的blog访问统计分析数据来看,使用IE6的还是占有绝对主流的。
<!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" alt="" style='width:387pt; height:133.5pt'> <v:imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image001.png" o:href="http://images.cnblogs.com/cnblogs_com/justinyoung/2007/vistorIE.png"/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
本来想顺便说说web标准中这个“标准”到底是个什么东西,但是发现,还是明日另起一篇吧。因为这个不是“顺便说说”就能说清楚的。我们今天还是不如这个正题——如何让层盖住下拉列表框?
非常郁闷或者非常幸运的说一下:这个问题只会出现IE7之前那些对web标准支持不好的浏览器中(例如现在非常主流的IE6 -_-b...),IE7和FF<!--[if gte vml 1]><v:shape id="_x0000_s1027" type="#_x0000_t75" alt="" style='position:absolute;left:0;text-align:left; margin-left:-45pt;margin-top:39pt;width:194.25pt;height:159pt;z-index:2; mso-wrap-distance-left:0;mso-wrap-distance-top:0;mso-wrap-distance-right:0; mso-wrap-distance-bottom:0;mso-position-horizontal:absolute; mso-position-horizontal-relative:text;mso-position-vertical:absolute; mso-position-vertical-relative:line' o:allowoverlap="f"> <v:imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image003.png" o:title="updivinIE6"/> <w:wrap type="square"/> </v:shape><![endif]--><!--[endif]-->都不会出现这个问题。
<!DOCTYPEhtmlPUBLIC"-//W<chmetcnv unitname="C" sourcevalue="3" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">3C</chmetcnv>//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CssJavascriptDemo</title>
<metaname="Generator"content="EditPlus"/>
<metaname="Author"content="JustinYoung"/>
<metaname="Keywords"content="CssStandardJavascriptDemo,B/S,JustinYoung"/>
<metaname="Description"content="ThisdemofromJustinYoung'sBlog:Yes!B/S!"/>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<styletype="text/css">
#divUp{
z-index:99;
position:absolute;
background-color:red;
width:100;
height:18;
overflow:hidden;
height:60px;
}
#ddlTest{
width:200;
z-index:1;
}
</style>
<body>
<divid="divUp">aaaaaaa<br>bbbbbbb<br>ccccccc</div>
<br/>
<selectid="ddlTest"><option>test0<option>test1<option>test2<option>test3</select>
</html>
<!--[if gte vml 1]><v:shape id="_x0000_s1026" type="#_x0000_t75" alt="" style='position:absolute;margin-left:9pt;margin-top:-23.4pt;width:60.75pt; height:64.5pt;z-index:1;mso-wrap-distance-left:0;mso-wrap-distance-top:0; mso-wrap-distance-right:0;mso-wrap-distance-bottom:0; mso-position-horizontal:absolute;mso-position-horizontal-relative:text; mso-position-vertical:absolute;mso-position-vertical-relative:line' o:allowoverlap="f"> <v:imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image007.png" o:title="div_select"/> <w:wrap type="square"/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
对于IE6,其实我们也并不是没有办法,虽然我们不得不承认这个办法很“挫”,但是这个是目前最有效的办法。那就是在下拉列表上方加一个iframe,然后让div层浮在iframe上方,这样,就能使div“盖住”下拉列表。如果你要问“为什么”,那么,首先恭喜你,你是个好同学,不像很多人只在网上找解决办法,而不是找知识(例如我-_-b...),然后我会告诉你,这个没有为什么,这个就是IE6的诡异解析。如果一定要问为什么,我只能告诉你,在IE6看来,如果只有div和select,无论你的z-index怎么设置,div的层永远被会被select标签踩在脚底,而iframe则可以爬到select头上,所以,下面的方法之所以能解决问题,是因为iframe在select上方,而div搭着iframe的顺风车也爬到了select的头上,这有点像这样:一条京叭狗(div)平时老是被大狼狗(select)踩到脚底欺负,这天,京叭的主人(iframe)抱着京叭把大狼狗踩到了脚底。这时候京叭自然就在大狼狗的头上了。扯远了,给出解决方案代码:
<!DOCTYPEhtmlPUBLIC"-//W<chmetcnv unitname="C" sourcevalue="3" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">3C</chmetcnv>//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CssJavascriptDemo</title>
<metaname="Generator"content="EditPlus"/>
<metaname="Author"content="JustinYoung"/>
<metaname="Keywords"content="CssStandardJavascriptDemo,B/S,JustinYoung"/>
<metaname="Description"content="ThisdemofromJustinYoung'sBlog:Yes!B/S!"/>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<styletype="text/css">
body{
font-size:small;
}
#zindexDiv{
position:absolute;
z-index:50;
width:expression(this.nextSibling.offsetWidth);
height:expression(this.nextSibling.offsetHeight);
top:expression(this.nextSibling.offsetTop);
left:expression(this.nextSibling.offsetLeft);
/*background-color:green;在ff中将这句话放出来,你就会明白京叭、狼狗、主人的比喻*/
}
#divUp{
z-index:99;
position:absolute;
background-color:red;
width:100;
height:18;
overflow:hidden;
height:60px;
}
#ddlTest{
width:200;
z-index:1;
}
</style>
<body>
<iframeid="zindexDiv"frameborder="0"></iframe>
<divid="divUp">aaaaaaa<br>bbbbbbb<br>ccccccc</div>
<br/>
<selectid="ddlTest"><option>test0<option>test1<option>test2<option>test3</select>
</html>
另外的一种解决办法:实验通过。原理是在div块中添加一个不可见的iframe。
<!DOCTYPE HTML PUBLIC "-//W<chmetcnv unitname="C" sourcevalue="3" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">3C</chmetcnv>//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<<place w:st="on">META</place> NAME="Generator" CONTENT="EditPlus">
<<place w:st="on">META</place> NAME="Author" CONTENT="">
<<place w:st="on">META</place> NAME="Keywords" CONTENT="">
<<place w:st="on">META</place> NAME="Description" CONTENT="">
</HEAD>
<BODY>
<div id="menu" style="position:absolute; visibility:hidden; top:20px; left:20px;
width:100px; height:200px; background-color:#6699cc;">
<table>
<tr><td>item 1</td></tr>
<tr><td>item 2</td></tr>
<tr><td>item 3</td></tr>
<tr><td>item 4</td></tr>
<tr><td>item 5</td></tr>
</table>
<iframe src="" style="position:absolute; visibility:inherit; top:0px; left:0px; z-index:-1; filter='progidXImageTransform.Microsoft.Alpha(style=0,opacity=0)';"></iframe>
</div>
<a href="#" οnclick="document.getElementById('menu').style.visibility='visible';">menu</a>
<form>
<select><option>A form selection list</option></select>
</form>
</BODY>
</HTML>