I have a problem with creating grid in flexbox according to following image layout. I spent two days figuring out how to solve it without making position:absoulte hacks. Can someone please help me to sort it out with flex good practise?
Asked
Active
Viewed 2,608 times
-5
-
2We can't help you unless you show us your code. – David May 10 '18 at 13:08
-
Have you tried `display: grid` and work using that? Flexbox is uni directional, grid can easily get you layout that you want. – Rikin May 10 '18 at 13:10
-
show code of what you have. make it a snippet – DCR May 10 '18 at 13:16
1 Answers
1
I am not a pro concerning flexbox, but Rikin seems right. Grid is way better for layouts like this.
In flexbox, you would have to put flex-container into flex-container, to get the layout you want. Try my code below and you will get the idea. You'd have to figure out the middle column on the left by yourself, though.
Cheers!
HTML
<div class="wrapper">
<div class="col-left">
<div class="col-left-row-1 color green">
Lorem 1
</div>
<div class="col-left-row-2 color yellow">
Lorem 2,3,4
</div>
<div class="col-left-row-3 color red">
Lorem 5
</div>
</div>
<div class="col-right color blue">
Lorem 6
</div>
</div>
CSS
.wrapper {
display: flex;
height: 500px;
color: darkblue;
}
.col-right {
flex-basis: 30%;
}
.col-left {
flex-basis: 70%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.red {
background-color: red;
flex-grow: 1;
}
.green {
background-color: green;
flex-grow: 3;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
flex-grow: 2;
}
.color {
padding: 30px;
margin: 2px;
}

Langer.197
- 78
- 8
-
Hi @langer-197 , thx for code snippet. I added 2,3,4 boxes in following snippet: https://codepen.io/anon/pen/jxzebb. It works great. thanks again – PawelS May 10 '18 at 21:25
-
1