Flexbox can't do that by itself in a flexible way.
As you mentioned yourself, CSS Grid can do this, though since you didn't want that, this suggestion is based on the assumption that you at narrower screens want the b
to be at the bottom.
By simply initially use float
, and then at a certain break point, swap between float
and display: flex
, it is very easy to take advantage of both.
Additionally, using Flexbox's order
property, one can easily position the elements in any desired order, and with this avoid script and get a reasonable level of browser support.
Updated codepen
Stack snippet
* {
box-sizing: border-box;
}
.cont {
background: gold;
overflow: hidden;
}
.a,
.b,
.c {
width: 45%;
padding: 10px;
float: left;
}
.a {
background: red;
}
.b {
background: blue;
color: white;
float: right;
}
.c {
background: orange;
}
@media (max-width: 500px) {
.a,
.b,
.c {
width: auto;
float: none;
}
.b {
order: 1;
}
.cont {
display: flex;
flex-direction: column;
}
}
<div class="cont">
<div class="a">
A
</div>
<div class="b">
B
<br>
More B
</div>
<div class="c">C</div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…