html - 弹性盒不拉伸
问题描述
我目前正在用 Flex Box 做一些事情,我希望我的 flex box 可以拉伸,但我做不到。这是我的代码笔: https ://codepen.io/chevalierv/pen/bGdBKyg
.FlexContainer {
height: 65vh;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: stretch;
align-content: stretch;
justify-content: center;
padding: 1em;
background-color: red;
}
.SecondChildContainer {
align-self: flex-end;
order: 2;
flex: 1;
flex-basis: 100%;
background-color: green;
}
.FirstChildContainer {
order: 1;
flex-grow: 5;
align-self: stretch;
background-color: blue;
}
<div class="FlexContainer">
<div class="FirstChildContainer">
a
</div>
<div class="SecondChildContainer">
a
</div>
</div>
解决方案
我已经清理了你的 CSS 并使它工作。请参阅下面的 jsfiddle:
https://jsfiddle.net/gqptemhu/
基本上,你的弹性容器需要的是
.FlexContainer {
height: 65vh;
display: flex;
flex-direction: column;
}
所以它知道垂直堆叠物品。
你用
flex: 0 1;
flex: 1 0;
在 flex 容器内的项目上,告诉哪些项目会增长,哪些项目会缩小。第一个数字对应于 flex-grow,第二个对应于 flex-shrink。它们都是相对数字,它们说明项目将增长/缩小到的空间百分比。
您可以在下面的链接中阅读有关 flexbox 以及如何使用它的更多信息:
推荐阅读
- curl - 不支持的媒体类型,即使没有在标头中传递任何 Content-Type
- docker - Traefik 和 https 私有存储库 - tls 错误
- java - 杰克逊注释不适用于多对多关系:无限循环
- f# - 将变量定义注入 F# 引用
- haskell - 为什么有一个用于 exceptT 的 MonadMask 实例?
- go - 有没有办法操纵延迟堆栈?
- ios - Flutter:未连接到 Android Studio 中的 IOS 模拟器
- c++ - 数组变量是 C++ 中的引用吗?
- asp.net - Web API 在控制器上未找到任何操作
- c++ - 修改 Makefile 以添加 GSL 库