如何让DIV层盖住下拉列表框? 问题解决方案

rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"> rel="Edit-Time-Data" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_editdata.mso">

如何让DIV层盖住下拉列表框? 问题解决方案.

参考:http://www.cnblogs.com/JustinYoung/archive/ 2007/07/18 /821868.html

首先,我们不得不承认IE7以前的IE系列浏览器对web标准支持的真的很差。IE6的诡异解析模式让一些开始学习web标准的朋友老是碰到不能理解的问题。特别是这个IE6IE7过渡的是非年代。IE6真的让人很郁闷。但是就目前而言,我们还是不能放弃对IE6的兼容。从下面的我的blog访问统计分析数据来看,使用IE6的还是占有绝对主流的。

本来想顺便说说web标准中这个标准到底是个什么东西,但是发现,还是明日另起一篇吧。因为这个不是顺便说说就能说清楚的。我们今天还是不如这个正题——如何让层盖住下拉列表框?

非常郁闷或者非常幸运的说一下:这个问题只会出现IE7之前那些对web标准支持不好的浏览器中(例如现在非常主流的IE6 -_-b... ,IE7FF 都不会出现这个问题。 出现上面情况的参考代码:

<!DOCTYPE html PUBLIC "-//W 3C //DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Css Javascript Demo</title>
<meta name="Generator" content="EditPlus"/>
<meta name="Author" content="JustinYoung"/>
<meta name="Keywords" content="CssStandard JavascriptDemo,B/S,JustinYoung"/>
<meta name="Description" content="This demo from JustinYoung's Blog:Yes!B/S!"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="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>
<div id="divUp">aaaaaaa<br>bbbbbbb<br>ccccccc</div>
<br/>
<select id="ddlTest"><option>test0<option>test1<option>test2<option>test3</select>
</html>


对于IE6,其实我们也并不是没有办法,虽然我们不得不承认这个办法很,但是这个是目前最有效的办法。那就是在下拉列表上方加一个iframe,然后让div层浮在iframe上方,这样,就能使div“盖住下拉列表。如果你要问为什么,那么,首先恭喜你,你是个好同学,不像很多人只在网上找解决办法,而不是找知识(例如我-_-b...),然后我会告诉你,这个没有为什么,这个就是IE6的诡异解析。如果一定要问为什么,我只能告诉你,在IE6看来,如果只有divselect,无论你的z-index怎么设置,div的层永远被会被select标签踩在脚底,而iframe则可以爬到select头上,所以,下面的方法之所以能解决问题,是因为iframeselect上方,而div搭着iframe的顺风车也爬到了select的头上,这有点像这样:一条京叭狗(div)平时老是被大狼狗(select)踩到脚底欺负,这天,京叭的主人(iframe)抱着京叭把大狼狗踩到了脚底。这时候京叭自然就在大狼狗的头上了。扯远了,给出解决方案代码:

<!DOCTYPE html PUBLIC "-//W 3C //DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Css Javascript Demo</title>
<meta name="Generator" content="EditPlus"/>
<meta name="Author" content="JustinYoung"/>
<meta name="Keywords" content="CssStandard JavascriptDemo,B/S,JustinYoung"/>
<meta name="Description" content="This demo from JustinYoung's Blog:Yes!B/S!"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="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>
<iframe id="zindexDiv" frameborder="0"></iframe>
<div id="divUp">aaaaaaa<br>bbbbbbb<br>ccccccc</div>
<br/>
<select id="ddlTest"><option>test0<option>test1<option>test2<option>test3</select>
</html>

另外的一种解决办法:实验通过。原理是在div块中添加一个不可见的iframe

<!DOCTYPE HTML PUBLIC "-//W 3C //DTD HTML 4.0 Transitional//EN">

<HTML>

 <HEAD>

  <TITLE> New Document </TITLE>

  < META NAME="Generator" CONTENT="EditPlus">

  < META NAME="Author" CONTENT="">

  < META NAME="Keywords" CONTENT="">

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值