整个早上我都在搜索这个问题,但似乎无法解决:
我有一个父级DIV相对定位,内部设置了两列子DIV,均为绝对定位。我需要父级DIV的高度随着内部DIV的内容而拉伸。
我尝试在#content的结束标记前加入.clearfix类型的代码,但没有浮动任何元素。我还尝试将float属性添加到#content div,但没有成功。有人能指点我正确的方向吗?很明显,我没有理解嵌套显示如何影响彼此。
CSS:
#content {
width: 780px;
padding: 10px;
position: relative;
background: #8b847d;
}
#leftcol {
width: 500px;
position: absolute;
}
#rightcol {
width: 270px;
position: absolute;
left: 500px;
margin-left: 10px;
text-align: center;
}
HTML:
<div id="content">
<div id="leftcol">
<p>Lorem Ipsum</p>
</div><!-- /leftcol -->
<div id="rightcol">
<img src="images/thumb1.jpg">
<img src="images/thumb2.jpg">
</div><!-- /rightcol -->
<br style="clear:both;">
</div><!-- /content -->