is there a way to auto adjust container DIV height to accommodate absolutely positioned child DIVs? i d like to get something like
+-----------------------+ | container | | +------+ +------+ | | | chld | | chld | | | | 1 | | 2 | | | | | | | | | +------+ +------+ | | +------+ | | | chld | | | | 3 | | | | | | | +------+ | +-----------------------+
我试着像:
<div class="container" style="position: relative; border: solid thin">
<div class="chld" style="width: 20px;
height: 20px;
position: absolute; left: 5px; top: 5px;
border: dashed thin;"><div>
<div class="chld" style="width: 20px;
height: 20px;
position: absolute; left: 30px; top: 5px;
border: dashed thin;"><div>
<div class="chld" style="width: 20px;
height: 20px;
position: absolute; left: 15px; top: 30px;
border: dashed thin;"></div>
</div>
但“容器”div保持零高度。我理解,这可能是预期的行为,作为元素的流当绝对定位,但是有一个解决方案吗?(除了precalculating产生的高度和手动设置)