This is my code for a website on which I have boxes, which on click lead user to another page for specific article. I use display: flex to show them in a 3x3x3 rows, but I want it to be displayed in a 3x2x3x2 style, so that first row has a width of 33%, but in the second row each box has a width of around 50%. Is it achievable in any way? I can't find any suitable solution on the internet.
HTML:
<div class="boxes">
<div class="box">
<a>
<div class="photo">...</div>
<div class="content">...</div>
</a>
</div>
<div class="box">
<a>
<div class="photo">...</div>
<div class="content">...</div>
</a>
</div>
<div class="box">
<a>
<div class="photo">...</div>
<div class="content">...</div>
</a>
</div>
</div>
CSS:
.boxes{
position: relative;
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: center;
column-gap: 20px;
rów-gap: 20px;
}
.box{
display: block;
position: relative;
width: calc(33.33%);
}
EDIT: of course I have more of these divs "box" but I just provided less to not make a mess
You can solve this with a CSS Grid by creating a 6-column grid. Then you let all elements span 2 rows and select every 4th and 5th element of a group of 5 elements to span 3 columns.
You also can do this with Flexbox, however which will not allow the usage with gap without complicated calculations. Here you can also sue the
nth-child()selector to select the 4th and 5th element of a group of 5 elements: