.page {
width: 90% margin: auto;
}
.row-container {
width: 100%;
display: flex;
}
.item-container {
flex: 1;
padding: 16px;
}
.item-container-2x {
flex: 2;
}
.item {
background-color: #e7e8e9;
height: 50px;
border: 1px solid #dddddd;
}
<div class="page">
<div class="row-container">
<div class="item-container">
<div class="item"></div>
</div>
<div class="item-container">
<div class="item"></div>
</div>
<div class="item-container">
<div class="item"></div>
</div>
</div>
<div class="row-container">
<div class="item-container item-container-2x">
<div class="item"></div>
</div>
<div class="item-container">
<div class="item"></div>
</div>
</div>
</div>
The issue here is with the paddings. It causes the grid on the second row to be misaligned.
I'm using flex: 1;
for the equal width grid items, and flex: 2;
next to one with flex: 1;
for the second row. My understanding is that the flex numbers add up. I'm trying to add them up to 3, but in the second row, having only one margin between the two grid items is impacting to spacing. I'm not sure if this approach is better than defining variable widths for the gird items, but using flex seems simple to me.
I think there's also a problem that I'm using fixed paddings of 16px
with the variable width withflex: 1/2
. I did try percentage margin and still had the same problem. And I'm having a hard time getting my head around needing to use a combination of padding and margin, and maybe even negative margin.
Thanks for any help.