html - 在 flexLayout 中使 div 尽可能大
问题描述
#container {
display: flex;
flex-direction: column;
align-items: center;
height: 200px;
width: 100px;
background-color: red;
}
#stack{
display: flex;
flex-direction: column;
align-items: center;
max-height: 200px;
}
.item {
display: flex;
height: 30px;
width: 100px;
background-color: green;
flex-shrink: 0;
}
.spacer {
display: flex;
height: 200px;
flex-shrink: 1000;
}
<div id="container">
<div class="stack">
<div class="item">a</div>
<div class="spacer"></div>
<div class="item">b</div>
</div>
</div>
如上面的代码所示,父级有一个max-height
,因为它的高度是未定义的。我希望的高度spacer
尽可能大。我期望的是160px
在这种情况下。我试过了flex-grow
,但它不起作用,因为容器没有height
. 我也尝试过flex-shrink
类似height
代码片段中的代码。但我发现有时flex-shrink
不起作用,或者有时它看起来很吓人,高度很大。
解决方案
它不起作用,因为您为“堆栈”使用了错误的选择器 - 它是一个类,而不是 id!这应该工作:https ://jsfiddle.net/bL5w81d4/1/
#container {
display: flex;
flex-direction: column;
align-items: center;
height: 200px;
width: 100px;
background-color: red;
}
.stack{
display: flex;
flex-direction: column;
align-items: center;
max-height: 200px;
}
.item {
display: flex;
height: 30px;
width: 100px;
background-color: green;
flex-shrink: 0;
}
.spacer {
display: flex;
height: 200px;
flex-shrink: 1000;
}
推荐阅读
- r - 从 PDF 文件中抓取表格
- macos - 在 Mac OS X 10.11.6 El Capitan 上安装 ffmpeg 时出现问题
- spring-boot - 如何在 Spring Security Oauth2 客户端中定义自定义授权类型?
- javascript - react-id-swiper 不适用于动态卡
- hyperledger-fabric - 在 HyperLedger 中查询历史资产状态
- graphql - 在 Gatsby 中对多个查询的 GraphQL 查询进行排序
- python - 如何指定路径中不存在的文件?
- google-cloud-functions - 用于向令牌集合发送 fcm 通知的云功能
- amazon-ec2-spot-market - 暂时停止 Spot 实例
- mysql - Hive 表到 MySQL 表的转换