明确的包装div包含ap divs
问题描述:
跑到一个地方,我绝对必须使用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
答
清除用于浮动,而不是绝对定位的元素。您无法清除绝对定位的元素。
答
你不能。您必须指定包装的高度以包含绝对定位的内部元素。绝对定位的元素不占用任何空间,因此包装环绕它们是不可能的。
在正确的上下文中使用ap ap div是很棒的。你不应该“失手”他们。
答
你可以得到最高孩子的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);
}
});
这个高度最高追加到父