2012-03-01 76 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>

參考