我想把子元素 DIV 放在父元素 DIV 的底部,同时希望子元素 DIV 的内容能够影响父元素 DIV 的尺寸。但是现在的情况是,子元素 DIV 并不能影响父元素 DIV 的宽度/高度。以下是我的 HTML/CSS 代码示例:
<div id="parent">
<h3>Top Aligned Title</h3>
<div id="child"></div>
</div>
//CSS 代码:
#parent {
background-color:#222;
position: relative;
height: 500px;
}
#child {
background-color:#444;
position: absolute;
bottom: 0px;
width: 100px;
height: 200px;
}
我需要做些什么才能实现我正在尝试做的事情?我可以放弃使用绝对/相对CSS规则,并在父DIV中创建一个表格,这将允许我实现底部对齐和指定父容器尺寸的内容。
但是,我想知道是否有一种方法可以在CSS中完成此操作,而无需设置父DIV的宽度。
先行致谢!