HTML:父块底部内的锚块元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1462799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:54:51  来源:igfitidea点击:

HTML: Anchor block element inside bottom of parent block?

htmlcsslayout

提问by recursive

Is there a cross browser method of attaching some content in a <div>to the bottom? One difficulty is that the <div>may have an arbitrary height applied, but I want certain content to be stuck to the bottom of it at all times.

是否有跨浏览器方法将 a<div>中的某些内容附加到底部?一个困难是<div>可能应用了任意高度,但我希望某些内容始终粘在它的底部。

This would have been accomplished in the bad old days like this:

这本可以在像这样的糟糕过去实现:

<table style="height: foo;">
    <tr><td valign="top">content</td></tr>
    <tr><td valign="bottom">stuck to the bottom</td></tr>
</table>

Can I do this without resorting to this technique?

我可以在不诉诸这种技术的情况下做到这一点吗?

回答by TJ L

Sure, it's pretty easy. Just set the parent divwith position:relative. Then, the inner item you want to stick to the bottom, just use position:absoluteto stick it to the bottom of the item.

当然,这很容易。只需div使用position:relative. 然后,你想粘在底部的内部物品,只需用position:absolute它粘在物品的底部即可。

<div id="parent">
    <div id="child">
    </div>
</div>

.

.

#parent {
  position:relative;
}
#child {
  position:absolute;
  bottom:0;
}