Move a column to the next row using Flex Box
I have three columns, of the order of 1,2,3.
HTML
<div class="flex-container">
<div class="item first">1</div>
<div class="item second">2</div>
<div class="item third">3</div>
</div>
CSS
.flex-container {
display: flex;
}
.item {
background: orange;
padding: 10px auto;
color: #fff;
font-family: arial;
flex-grow: 100;
flex-shrink: 50;
text-align: center;
}
.first {
order: 1;
}
.second {
order: 2;
}
.third {
order: 3;
}
What I want, when I switch to the columns of the mobile screen, should be displayed as follows:
1 3
2
Media request
/* Too narrow to support three columns */
@media all and (max-width: 640px) {
.second {
order: 3;
/* And go to second line */
}
.third {
order: 2;
}
}
Column two should go to the next row.
Any help? thank
+4
1 answer
flex-direction - row, column flex-wrap:wrap ( flex-flow:column wrap). , .flex-container , .first .second , , 3 . , .third expand/strecth ( ). flex-grow:0 flex-basis:50%. :
@media all and (max-width: 640px) {
.flex-container {
flex-flow:column wrap;
height:40px;
}
.third {
flex-grow:0;
flex-basis:50%;
}
}
, flex-box, .
2
+7