IE6下select下拉框覆盖div的问题

来源:互联网 发布:知豆汽车是哪家公司的 编辑:程序博客网 时间:2024/05/22 17:19

测试代码:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title>Untitled Document</title>
 </head>
 <body>
  <div style="position:absolute;background:red;width:100px;height:200px;z-index:10000;left:20px;top:20px;"></div>
  <select><option>sdf</option></select>
  dfgdfgdfgdfgdfgdfgdfgdfgdfdfgdfgdfgdfgdfgdfgdfgdfgddfgdfgdfgdfgdfgdfgdfgdfgd
  dfgdfgdfgdfgdfgdfgdfgdfgdf 
 </body>
</html>

 

先看看IE6下效果:

       IE8下:

                       

可见,这是极其难看的,无论层的z-index设到多少亿都是没用的,目前没发现完美的解决方法,都是存在bug的,本人现知道的有2种:

1.显示层之前隐藏全部select,此方法影响效率,也影响布局美观。

2.在层里插入一个隐藏iframe,奇怪的是,iframe可以覆盖select,需要设置iframe为浮动,透明度为0,IE6效果:

代码,IE6-8、firefox3.5、safari4、opera9测试下通过:

<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title>Untitled Document</title>
 </head>
 <body>
  <div style="position:absolute;background:red;width:100px;height:200px;left:20px;top:20px;">
   <iframe style="position:absolute;width:100%;height:100%;_filter:alpha(opacity=0);opacity=0;border-style:none;"></iframe>
   sdfsdfsdf<br>sdfsdfsdf<br>sdfsdfsdf<br>sdfsdfsdf<br>
  </div>
  <select><option>sdf</option></select>
  dfgdfgdfgdfgdfgdfgdfgdfgdfdfgdfgdfgdfgdfgdfgdfgdfgddfgdfgdfgdfgdfgdfgdfgdfgd
  dfgdfgdfgdfgdfgdfgdfgdfgdf  
 </body>
</html>

完。

原创粉丝点击