css - CSS Flex - 如果内容更宽,则切换到行的列?
问题描述
我正在尝试实现以下布局:
<Column 1, 50%> <Column 2, 50%>
根据某些条件,第 2 列的内容可能会更长,在这种情况下,它现在应该被推到第二行并占据 100% 的宽度。这意味着现在两者都将是行。
<Row 1 (was Column 1), 100%>
<Row 2 (was Column 2), 100%>
现在我被困在等宽的列上,第二列的内容更宽,垂直增长。
解决方案
只是一个带有flex-wrap
?
.my-layout {
display: flex;
flex-wrap: wrap;
}
.my-layout > * {
flex: 1 0 auto;
/* optional: determine the minimum width of the cell before it breaks into the next line */
min-width: 45%;
}
<div class="my-layout">
<div style="background-color: salmon;">First Line</div>
<div style="background-color: steelblue;">Second Line</div>
</div>
<br>
<div class="my-layout">
<div style="background-color: salmon;">First Line First Line First Line First Line First Line First Line First Line First Line </div>
<div style="background-color: steelblue;">Second Line</div>
</div>
推荐阅读
- java - java.io.IOException: error=12, 无法分配内存
- android - appcompat-v7:27.1.1 CardView 未在以前的 api 中显示
- intellij-idea - Linux Mint 19 Cinnamon 上的 IntelliJ IDEA Ultimate 渲染不良
- swift - 如何在 Vapor 3 中将字典转换为 JSON?
- javascript - 未处理的拒绝(TypeError):res.map 不是函数
- python - OpenTracing Python 请求:传播跨度
- java - Java 的正则表达式引擎是否在内部优化了字符类表达式?
- c# - 如何检查我是否在 if 语句中越界?
- sql - Excel VBS/SQL 完全混乱
- java - 将工厂方法放在抽象父类中