2011-01-12 66 views
0

跑到一個地方,我絕對必須使用ap div。問題是:我無法找到一種方法來清除我的包裝div。我的竅門沒有任何工作。明確的包裝div包含ap divs

我想失去包裝div的高度設置,仍然包含ap div。

任何想法?

<pre> 
<code> 
#wrapper { 
position:relative; 
width:600px; 
height:1200px; --- wanna dump this but can't find way to clear 
margin-right: auto; 
margin-left: auto; 
background-color: #0CF; 
z-index:100; 
} 
#apDiv1 { 
position:absolute; 
width:200px; 
height:115px; 
z-index:1001; 
left: 89px; 
top: 329px; 
background-color: #0C0; 
} 
#apDiv2 { 
position:absolute; 
width:100px; 
height:50px; 
z-index:1000; 
left: 383px; 
top: 36px; 
background-color: #F39; 
} 

div id=wrapper 
    div id=apDiv1 closediv 
    div id=apDiv2 closediv 
div-- close wrapper 

回答

0

清除用於浮動,而不是絕對定位的元素。您無法清除絕對定位的元素。

0

你不能。您必須指定包裝的高度以包含絕對定位的內部元素。絕對定位的元素不佔用任何空間,因此包裝環繞它們是不可能的。

在正確的上下文中使用ap ap div是很棒的。你不應該「失手」他們。

0

你可以得到最高孩子的jQuery下面

var t=0; // the height of the highest element (after the function runs) 
var t_elem; // the highest element (after the function runs) 
$("*",elem).each(function() { 
    $this = $(this); 
    if ($this.outerHeight() > t) { 
     t_elem=this; 
     t=$this.outerHeight(); 
     alert(t); 
    } 
}); 
這個高度最高追加到父