I am trying to use a nested flexbox layout in order to achieve the following layout when there is a certain amount of space:
Then, when there isn't enough space, the right-hand side should wrap to a row layout instead of a column layout, so that the boxes are side-by-side when they wrap, example:
The idea is to have the boxes on the right 50% of the left content so that when they wrap underneath, they are the same combined size as the left content.
However, I can't figure out how to do this via flexbox only. This is what I have so far, but if you resize the window you'll see that the boxes stay in the same direction:
http://jsfiddle.net/usLxshro/
div {
min-height: 50px;
background: #E7E7E7;
margin: 10px;
}
#wrapper {
display: flex;
flex-wrap: wrap;
}
#left-content {
flex: 2;
min-width: 200px;
}
#right-content {
flex: 1;
min-width: 200px;
}
section {
border: 1px solid #333;
margin: 10px;
}
CSS Demo: flex-directionIf its dir attribute is ltr , row represents the horizontal axis oriented from the left to the right, and row-reverse from the right to the left; if the dir attribute is rtl , row represents the axis oriented from the right to the left, and row-reverse from the left to the right.
default flex-direction: row; The flexbox items are ordered the same way as the text direction, along the main axis. flex-direction: row-reverse; The flexbox items are ordered the opposite way as the text direction, along the main axis.
wrap-reverse. Specifies that the flexible items will wrap, if necessary, in reverse order. Demo ❯ initial. Sets this property to its default value.
You can use media-queries to change behavior
@media (max-width: 500px) {
#wrapper {
flex-direction: column;
}
#right-content {
display: flex;
}
section {
flex: 1;
}
}
See updated fiddle — http://jsfiddle.net/shurshilin/usLxshro/1/
Hope it'll help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With