css - 当容器和​​内容高度都未知时,如何将内容刷新到容器底部?

标签 css

我有这种情况:http://liveweave.com/roBPrb .这是来源:

HTML:

<div class="container">
  <div class="content">
    This should be always at<br/>
    the bottom, the container<br/>
    should grow with the texts size.
  </div>
</div>

CSS(忽略颜色):

.container {
  min-height: 200px;
  border: 1px solid green;
}

.content {
  background-color: red;
}

我想要两件事:

  • 容器应随着内容的增加而增大。
  • 内容应始终位于容器底部。

我该怎么做?它应该与 IE >= 9 和其他浏览器的现代版本兼容。

最佳答案

这应该有效:

.container {
  max-height:100%;
  min-height: 200px;
  height:auto;
  border: 1px solid green;
  position: relative;
}

.content {
  background-color: red;
  position: absolute;
  bottom:  0;
  left: 0;
}

请注意,父容器必须具有相对位置才能使子容器的绝对定位起作用。我希望你找到了你要找的东西。

关于css - 当容器和​​内容高度都未知时,如何将内容刷新到容器底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27194982/

相关文章:

jquery - Bootstrap 下拉按钮不起作用

html - Internet Explorer 忽略 div 的宽度

html - Google 阅读器菜单如何保持原样?

CSS:将溢出:隐藏应用于同级

jquery - 使用 jquery 检查 css 底部

html - IE9 不渲染元素的边框

通过脚本的 HTML 音频控制

javascript - 通过 jQuery 创建新的 DOM 元素时,为什么要向它们添加空的 Style 属性?

css - IE 6 问题背景中的 png 图片

css - 一组两个元素到 'add' 到我的文本区域不与页面对齐