今天碰到一个关于IE6下display:none的bug,纠结很久,终于找到解决的办法。

代码例子如下

<div style="width:300px; margin:20px; border:1px solid #000; overflow:hidden; zoom:1;">   

<div style="background:green; width:10px; float:left; height:300px;"></div>   

<div style="background:red; float:left; height:300px; width:280px;"></div>   

<div style="display: none; "></div>   

<div style="background:green; width:10px; float:left; height:300px;"></div>   

</div> 

这个是有在ie6下如图

display:none引起的3像素的BUG
 

其他浏览器如图:

2009-08-19_192652

这个问题真是让人郁闷,感谢greengnn和广州♂锋提供的解决方案:

解决方案1:将最后一个div加一个margin-right:-3px;即

  1. <div style="width:300px; margin:20px; border:1px solid #000; overflow:hidden; zoom:1;">   
  2. <div style="background:green; width:10px; float:left; height:300px;"></div>   
  3. <div style="background:red; float:left; height:300px; width:280px;"></div>   
  4. <div style="display: none; "></div>   
  5. <div style="background:green; width:10px; float:left; height:300px;margin-right:-3px"></div>  

解决方案2:将display: none的div换一个形式隐藏:即
 

    1. <div style="width:100px; margin:20px; border:1px solid #000; overflow:hidden; zoom:1;">   
    2. <div style="background:green; width:10px; float:left; height:100px;"></div>   
    3. <div style="background:red; float:left; height:100px; width:80px;"></div>   
    4. <div style="position:absolute; visibility: hidden "></div>   
    5. <div style="background:green; width:10px; float:left; height:100px; margin-right:-3px"></div>   
    6. </div>
posted on 2013-07-05 22:55  潇逸丶  阅读(694)  评论(0)    收藏  举报