html - 垂直拉伸(stretch)div内的div

标签 html css

<分区>

我正在尝试创建一个框,其中的内容总是将 100% 的高度带到底部(减去填充),即使它已调整大小并且内容很小。我被想法困住了……感谢所有建议!

还有一支笔:https://codepen.io/Dalmat/pen/VOmxzm

.box {
  background: lightblue;
  width: 200px;
  min-height: 100px;
  padding: 10px;
  text-align: center;
  overflow: auto;
  resize: both;
}

.box_bottom {
  background: darkblue;
  color: white;
}
<div class="box">
  <div class="box_top">
    Title
  </div>
  <div class="box_bottom">
    Content
  </div>
</div>

最佳答案

Flexbox 对于这样的东西非常方便。 Flexbox 的完整指南是一篇值得阅读的好文章:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

.box {
  background: lightblue;
  width: 200px;
  height: 100px;
  padding: 10px;
  text-align: center;
  
  display: flex;
  flex-direction: column;
  justify-content: stretch;
}

.box_bottom {
  background: darkblue;
  color: white;
  height: 100%;
}
<div class="box">
  <div class="box_top">
    Title
  </div>
  <div class="box_bottom">
    Content
  </div>
</div>

关于html - 垂直拉伸(stretch)div内的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56129788/

上一篇:css - canvas 元素看起来像是被填充了,但是 css 说它不是

下一篇:HTML:为什么文字比图片低一段? (有图)

相关文章:

javascript - Jquery 麻烦!!负载 ("");

javascript - 是否可以快速连续地重新加载 iframe?

css - Angular Material2 - 以编程方式设置颜色

CSS Dropdown 不显示但位于右侧

IE 8 中的 jQuery css 切换错误

html - 如何编辑嵌入式网页的样式表?

javascript - 从浏览器启动 dialer.exe?

javascript - .click 不适用于更改选项卡容器的高度

css - 使子 div 填充到其容器的高度,而不使用任何显式高度

具有相同填充的 x ​​个选项卡的 CSS 导航