2011-01-05 116 views
87

我們有兩個DIV,一個嵌入其他。如果外部DIV沒有絕對定位,那麼位於絕對位置的內部DIV不服從外部DIV隱藏的溢出(example)。位置絕對和溢出隱藏

是否有任何機會讓內部DIV服從外部DIV隱藏的溢出,而不將外部DIV設置爲絕對位置(會導致我們完整的佈局)? 我們的內部DIV的相對位置也不是一個選項,因爲我們需要「擴大」表TD(exmple)。

還有其他的選擇嗎?

回答

207

使外部<div>position: relative和內部<div>position: absolute。它應該適合你。

+3

多虧了你們倆。我一直認爲職位:相對是默認的。我剛剛瞭解到靜態是默認設置。我接受shankhans的答案,因爲兩個答案都是相同的,而shankhan需要更多點數;-) – Zardoz 2011-01-05 15:38:47

+0

@ Zardoz:謝謝 – shankhan 2011-01-06 05:34:06

+9

你忍者,你。 – 2012-10-24 21:59:56

21

position: relative對於外部div呢?在隱藏內部的例子中。由於不指定頂部或左側,因此它也不會將其移動到其佈局中。

-4

你讓div就像這樣:

<div style="width:100px; height: 100px; border:1px solid; overflow:hidden; "> 
    <br/> 
    <div style="position:inherit; width: 200px; height:200px; background:yellow;"> 
     <br/> 
     <div style="position:absolute; width: 500px; height:50px; background:Pink; z-index: 99;"> 
      <br/> 
     </div> 
    </div> 
</div> 

我希望這個代碼將幫助你:)