I am trying to create a responsive layout using flexbox where one pair of items (two and four) need to be stacked, next to section three when on a large screen, but then on narrow screens, the order needs to change so that they are stacked, one, two, three, four.
I've got a solution, but it isn't DRY, as you can see in the snippet I have duplicated section four.
Is it possible to achieve this using flexbox without the duplication?
.container {
display: flex;
flex-wrap: wrap;
width: 100%;
border: 1px solid red;
}
.section {
border: 1px solid green;
flex-grow: 1;
}
.one, .two, .four {
width: 100%;
}
.sub-container {
display: inline-flex;
flex-direction: column;
width: 50%;
}
.mobile-only {
display: none;
}
@media (max-width: 600px) {
.container {
flex-direction: column;
}
.sub-container {
width: 100%;
}
.section {
width: 100%;
}
.desktop-only {
display: none;
}
.mobile-only {
display: block;
}
}
<div class="container">
<div class="section one">One</div>
<div class="sub-container">
<div class="section two">Two</div>
<div class="section four desktop-only">Four</div>
</div>
<div class="section three">Three</div>
<div class="section four mobile-only">Four</div>
</div>