So I got this three column layout example from stackoverflow, but I'm trying to get both columns and rows using flexbox.
My ultimate goal is to have a three column layout (the left side be pictures, and the two columns to the right to be text).
However, I need everything to be lined up (the text and the images be aligned on the same axis).
But my problem is that when I try and space out the elements in the columns using margin-bottom
, only the text column one is working (and not the image one) and I can't figure out why.
I want the left column margin-bottom
to work as well. But even when I add margin-bottom
for all columns only the ones with the divs work.
Should I put my images in divs as well?
Here's an image of the problem I'm facing:
* {
margin: 0;
}
html,
body {
height: 100%;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
width: 80%;
height: 100%;
margin: 0 auto;
}
.left {
display: flex;
flex-flow: column wrap;
align-items: flex-start;
justify-content: flex-start;
order: 1;
background: red;
flex-basis: 100%;
height: 100%;
}
.middle {
display: flex;
flex-flow: column wrap;
align-content: flex-start;
justify-content: flex-start;
order: 3;
background: green;
flex-basis: 100%;
height: 100%;
}
.right {
order: 2;
background: yellow;
flex-basis: 100%;
height: 100%;
}
.box {
display: flex;
flex-flow: column wrap;
align-items: flex-start;
justify-content: flex-start;
height: 50px;
width: 50px;
}
@media screen and (min-width: 600px) {
.container {
flex-wrap: nowrap;
}
.left {
flex-basis: 1;
order: 1;
}
.middle {
flex-basis: 1;
order: 2;
}
.right {
flex-basis: 1;
order: 3;
}
}
.left,
.right,
.middle * {
margin-bottom: 25%;
}
<div class="container">
<div class="left">
<img src="cat1.jpeg" alt="cat">
<img src="cat1.jpeg" alt="cat">
</div>
<div class="middle">
<div class="box">`
<p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
</div>
<div class="box">`
<p>texteiehiefief texteiehiefief texteiehiefief texteiehiefief</p>
</div>
</div>
<div class="right"></div>
</div>