如何设置 div 来自父 div 的绝对位置

How to set div absolute position from the parent div

我需要输出一些 divs,其中包含绝对定位的子 divs:

<div class="parent">
    <div class="child">
     Some content 1.
    </div>
</div>
<div class="parent">
    <div class="child">
     Some content 2.
    </div>
</div>
<div class="parent">
    <div class="child">
     Some content 3.
    </div>
</div>
.parent {
    position: relative;
    margin-top: 50px;
}
.child {
    position: absolute;
    top: 0;
    left: 10;
    width: 200px;
    height: 200px;
}

但我的麻烦是子 div 一个接一个地堆叠,我希望它们垂直显示,一个接一个。我可以通过为父 div:

指定高度来做到这一点
.parent {
    position: relative;
    margin-top: 50px;
    height: 200px;
}

但是有没有不指定高度的方法呢?

我创建了一个 fiddle:

http://jsfiddle.net/n38546ca/1/

感谢任何帮助。

给 .parent 添加一个 (padding-top: 50px;) div

.parent { position: relative; margin-top: 50px; padding-top: 50px; }