css - Flexbox 3-Cols 100% 高度
问题描述
我知道有类似的问题,但我只是不明白。
我的网站使用 Flexbox(行)有 3 列彼此相邻。
我想要的是每列将屏幕高度填充到 100%。当然,布局仍然应该是响应手机的。
<div class="flex-container">
<div class="flex-col col1">Stuff</div>
<div class="flex-col col2">Stuff</div>
<div class="flex-col col3">Stuff</div>
</div>
CSS:
.flex-container {
position: relative;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
overflow: hidden;
align-items: stretch;
}
.col {
text-align: center;
width: 400px;
font-size: small;
padding:20px;
}
.col1 {
background-color: grey;
}
.col2 {
background-color: red;
flex-grow: 2;
}
.col3 {
background-color: green;
flex-grow: 1;
}
解决方案
你可以height: 100vh;
为每个flex-col
班级使用。
.flex-container{
position: relative;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
overflow: hidden;
align-items: stretch;
}
.col{
text-align: center;
width: 400px;
font-size: small;
padding:20px;
}
.col1{
background-color: grey;
}
.col2{
background-color: red;
flex-grow: 2;
}
.col3{
background-color: green;
flex-grow: 1;
}
.flex-col {
height: 100vh;
}
<div class="flex-container">
<div class="flex-col col1">Stuff</div>
<div class="flex-col col2">Stuff</div>
<div class="flex-col col3">Stuff</div>
</div>
推荐阅读
- vb.net - VB跟踪高低数字
- c++ - l-value ref 和 r-value ref 和 non-ref 类型的完美转发可变参数模板?
- vue.js - 你如何在路由器视图中传递数据
- python - TypeError:'int' 对象不可迭代。遍历字符串数据中的每个字符串时
- excel - 使用 2 行中的 2 个条件计算唯一值
- maple - 如何使用 Maple 中已被视为常量的符号?
- c++ - 调用 FreeLibrary 后字符串不会从内存中删除
- html - 如何保持标题背景图像的纵横比?
- excel - Excel - 放置更改单元格的文本
- javascript - 悬停时模糊整个背景