【发布时间】:2011-07-05 09:24:35
【问题描述】:
#Container {
width: 500px;
height: 600px;
}
#TheElement {
width: 500px;
height: 100px;
background-color: #000000;
}
我如何让#TheElement 被锁定到#Container 的最底部,而不管容器内的其他内容如何,而没有一堆边距欺骗?
【问题讨论】:
#Container {
width: 500px;
height: 600px;
}
#TheElement {
width: 500px;
height: 100px;
background-color: #000000;
}
我如何让#TheElement 被锁定到#Container 的最底部,而不管容器内的其他内容如何,而没有一堆边距欺骗?
【问题讨论】:
你可以使用relative absolute positioning:
#Container {
width: 500px;
height: 600px;
position: relative
}
#TheElement {
width: 500px;
height: 100px;
background-color: #000000;
position: absolute;
bottom: 0;
left: 0;
}
【讨论】:
position: absolute 实际上是相对于最近的父元素 positioned。