html - 垂直拉伸 div 内的 div
问题描述
我正在尝试创建内容总是将 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>
推荐阅读
- node.js - 为什么 Websocket/ws 在单核上连接套接字?(Nodejs/集群)
- javascript - reCAPTCHA - textarea g-recaptcha-response 不起作用
- jgrapht - 如何使用CSVImporter和创建顶点供应商
- java - 使用 Gradle 捆绑 java/处理应用程序
- java - 试图将类中的整数对象转换为字符串
- asp.net-web-api - 从 Angular 8 传递的 Http 标头未出现在 ASP.NET Core API 3.1 的 HttpContext 中
- python-3.x - 使用 matlab.engine 运行 python 脚本,无需安装 MATLAB
- react-native - 如何获取 json 并在 flatlist 中显示 img(React Native)
- ios - typeMismatch(Swift.DecodingError.Context(codingPath: [], debugDescription: "期望解码字典
但找到了一个数组。”)) - sql - 从两个表中创建表,它们之间没有链接