html - 当其父级具有最小高度时,如何使按钮占用所有可用空间?
问题描述
我在弹性框中有一个按钮。我想占用尽可能多的空间,但我也希望这个弹性框有一个最小高度,因为在你点击这个按钮后它会被动态文本替换。如果这个动态文本真的很长,我想让 flex 框增加高度,以便所有文本都适合。
这是我尝试过的:https ://codepen.io/tietyt/pen/xxZRYdd
<div class="container">
<button disabled="" tabindex="0"> Text </button>
</div>
.container {
display: flex;
flex-direction: column;
margin-bottom: 3em;
width: 100%;
text-align: center;
border-style: outset;
min-height: 5em;
}
.container button {
align-self: stretch;
}
解决方案
根据您所描述的,我认为您正在寻找
flex: auto;
如果您将该规则添加到您的按钮,那么它应该占用其父容器内的所有可用空间。
根据MDNflex
文档:
汽车
该项目根据其宽度和高度属性调整大小,但会增长以吸收弹性容器中的任何额外可用空间,并缩小到最小尺寸以适应容器。这相当于设置“flex: 1 1 auto”。
推荐阅读
- python - 在 TensorflowServing 中部署预训练的 Inception 失败:SavedModel 没有变量
- python - array.array() 如何使用这么小的内存空间?
- r - 使用 dplyr 按多个因素汇总逻辑值和分组
- c# - 更改单元格绑定值并更新 Datagrid
- wordpress - htaccess 重定向不会转到 https
- swift - 在 Swift 中使用 UISwitch 隐藏按钮
- r - 博客文章在 build_site 和 serve_site 之后未呈现
- javascript - 如何在 Adobe (javascript) 中将“秒”转换为 mm:ss:ll?
- python-3.x - 计算包含值 pandas 的列
- javascript - 是否可以定期或在特定日期推送通知?| 网络推送