Is there a way to get 2 column layout that is transformed to a 1 column layout with a media query?
Conditions for 2 column layout:
- items should flow one after another within columns
- items within columns will have different heights
- item position (order) can be imposed by html markup element position
Conditions for 1 column layout:
- items should flow one after another
- items within columns will have different heights
- item position (!) cannot be imposed by html markup (should be controlled over css)
I have been considering two separate containers for columns - but that construct blocks me for reordering (mix) elements between columns when layout becomes 1 column. I seems that all elements should be placed within one container - then for 1 column layout flex can be used for reordering, but how to achieve 2 column layout in that case?
To simulate media query behaviour remove class "one-column" from main container.
<div id="container" class="one-column"> -> <div id="container" class="">
In this concept the main problem is that items within columns (2 column layout) are not flowing directly one after another (there are gaps between items in the right column).
Here's what I achieved so far:
* {
box-sizing: border-box;
}
div {
width: 100%;
height: 100px;
float: left;
}
#container.one-column {
display: flex;
flex-direction: column;
height: auto;
}
#container {
display: block;
}
.col1 {
width: 60%;
background-color: red;
height:300px;
float: left;
}
.col2 {
width: 40%;
background-color: blue;
border: 1px solid white;
float: right;
}
.one-column > div {
width: 100%;
}
<div id="container" class="one-column">
<div class="col1" style="order:2;">
ONE
</div>
<div class="col2" style="order:1;">
TWO
</div>
<div class="col1" style="order:4;">
THREE
</div>
<div class="col2" style="order:3;">
FOUR
</div>
</div>
JSFiddle: https://jsfiddle.net/3b6htt1d/40/