Thanks to flexbox, based on this code, I would like col-1, col-3 and col-5 to be placed below each other in a column on the right and col-2 and col-4 to be placed below each other. below the others in a left column.
<div class="row">
<div class="col-1">TEXTE 1</div>
<div class="col-2">VIDEO 1</div>
<div class="col-3">TEXTE 2</div>
<div class="col-4">VIDEO 2</div>
<div class="col-5">TEXTE 3</div>
</div>
Is it possible ?
The desired result: texts on the left and videos on the right.
I tried this CSS but the videos stay below the texts. Columns do not work.
section.cta-video .row{
display: flex;
flex-direction: column;
justify-content: space-between;
}
section.cta-video .row .col-1, section.cta-video .row .col-3, section.cta-video .row .col-5 {
order: 1;
flex-basis: 50%;
}
section.cta-video .row .col-2, section.cta-video .row .col-4 {
order: 2;
flex-basis: 50%;
}
2
Answers
You can use grid, in particular
grid-template-areas
to solve this:More info on grid-template-areas on CSS tricks here
Is it necessary that it’s a
flex
layout?You can achieve this easily using
grid
.grid-template-columns: 1fr 1fr
turns it into a 2-column layout.You can then use the
nth-child
pseudo selectors to select all even-numbered children to start in the first grid column, and all the odd-numbered children to start in the second grid column: