2011-12-15 42 views
0

我在另一個div內有一個div。外部div的起始寬度爲& 0px的高度&高度緩慢增加,這產生緩慢顯示內部div(從中心向外)的效果。將固定應用於內部分區禁用溢出:隱藏?

我這樣做使用Javascript setInterval &只是增加每個迭代的外部div的尺寸。

因爲外層div被絕對定位我發現我需要recentre(HORIZ & VERT)外div來內內的div確保我透露從確切中心向外股利作爲外層div擴展。

是否有一種自動方式來確保內部div始終居中在外部div內部,因爲它會展開?使用CSS或其他方法?

我發現最好的辦法是,如果我改變了內部的div位置固定但隨後的溢出:隱藏(在外層div)犯規獲得adherred到???

<html> 
<head> 
</head> 
<body> 

    <!-- Using Javascript I will slowly increase the outer divs width & height: making the innerdiv slowly appear. 
     Although, as the outer div resizes, the inner div will be positioned relativly, how can I keep its position at 20,20 of the body ALL the time? --> 
    <div style="position: absolute; background-color: blue; left: 10px; top: 10px; width: 300px; height: 300px; overflow: hidden;"> 
     <div style="position: fixed; background-color: red; left: 20px; top: 20px; width: 500px; height: 300px;"> 
     </div> 
    </div> 

</body> 
</html> 

回答

0

如果你不需要IE7的支持,我建議你使用display:table-cell來實現垂直居中。

http://jsfiddle.net/fte2t/1/

如果你確實需要IE7,唯一方法是通過使用表,我怕...