Obviously is something more complicated but i’d like a clear and simple description
I tried with grid and flexbox layout, setted "align-self: center" to the right box, but nothing happens, asked to ChatGPT and Perplexity too but I’m stuck.
I just want to display the third box (in a possible flex or grid layout of 3 box) in the right, centered in the middle of first and second left box.
This is the example code:
.container {
display: flex;
flex-wrap: wrap;
width: 100%;
gap: 1.5rem;
}
.box {
background-color: #fff;
border: 2px solid #000;
}
.box1,
.box2 {
flex: 1 1 calc(60% - 1.5rem);
height: 250px;
}
.box3 {
flex: 1 1 calc(40% - 1.5rem);
height: 250px;
align-self: center;
}
<div class="container">
<div class="box box1"></div>
<div class="box box2"></div>
<div class="box box3"></div>
</div>
3
Answers
CSS-Grid with five rows would be ideal. Each box spans two rows.
Maybe you can do it with CSS grid, and adjust the max-width or the columns:
in grid-template-columns, you can adjust the number for less or more size in the boxes, or you can do it with max-width too. I use grid-column-start and grid-column-end for better understanding of whats happening.
I hope that might help, it’s my first time commenting in here. I think it was more practical to add the two layouts in the HTML, and I erased the box1, box2, box3 class since everything is applied to the layout:
You can just give diferent widths or flex to the layout1 and 2 or to the boxes inside if you wanna see a different size 🙂
Hope that helps!
ps. in your case, trying to align with align-self won’t work since there’s only one row, and you can’t make it go through those limits without using margins, which is definitely not recommended.