如何增加具有相对位置的父元素的高度,该父元素基于具有绝对位置的子元素的高度。
在下面的示例中,.parent 元素的高度显示为 0px。
注:我不想使用任何脚本
期望结果:
实际结果:
HTML 代码:
<div class="parent">
<div class="child" style="top:20px;">Hello</div>
<div class="child" style="top:40px;">Some content</div>
<div class="child" style="top:60px;">Some more content</div>
</div>
CSS:
.parent{position:relative;background:green;height:100%;border:1px solid #000000;width:250px;}
.child{position:absolute;}