Reputation: 78545
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:
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;
}
Upvotes: 18
Views: 17523
Reputation: 766
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.
Upvotes: 15