2012-03-01 48 views
1

我在怪癖模式下遇到了IE8问题。我有一个包含两个内部div的外部div元素。在IE8怪癖模式下相邻div之间奇怪的差距

<div style="margin-left:160px; margin-top:10px; margin-right:0px; height:10px; background:blue;"> 
    <div style="position:relative; float:left; width:10px; height:10px; background:orange;"></div> 
    <div style="position:relative; margin-left:10px; margin-right:0px;height:10px; background:green;"></div> 
</div> 

内部div应该跨越整个wrapper div,并且它在firefox和chrome中工作正常。但是当我在IE8中查看这个时,橙色div和绿色div之间有一个奇怪的差距。有谁知道如何解决这个问题(或解决它)?另外,我无法在文档中的任何位置放置文档类型声明。

回答

0

使用上的内容和相对定位在容器上的怪癖模式绝对定位:

<html lang="en"> 
 
    <head> 
 
     <title>Quirksmode Tests</title> 
 
    </head> 
 
    <body> 
 
     <div style="position:relative; margin-left:160px; margin-top:10px; margin-right:0px; height:10px; background-color:blue;"> 
 
      <div style="position:absolute; top:0; width:100%; right:0; height:10px; background-color:green;"></div> 
 
      <div style="position:absolute; top:0; left:0; width:10px; height:10px; background-color:orange;"></div> 
 
     </div> 
 
    </body> 
 
    </html>

参考