Hi everyone,
I’m facing an issue with my size grid where the last size box is not properly aligned with the rest of the items. It appears slightly off in terms of width, causing misalignment at the end of the grid. I need the size grid to be compatible across all screen sizes and devices, and I want to ensure the grid looks consistent on both desktop and mobile views.
Here’s the relevant part of my base.css file:
Despite using this, the last size box (when fewer items are in a row, such as 3 or 4 instead of 6) is slightly misaligned, creating gaps at the end of some rows.
Could someone suggest how to make the size grid fully responsive, ensuring proper alignment across all screen sizes and devices?
Thank you in Advance.
Hello. 
If you don’t need Flexbox’s one-dimensional flow, set the display to grid and use box-sizing: border-box to include any border and/or padding in its sizing so you don’t get unexpected misalignments:
.sizes-grid {
display: grid;
grid-gap: 1rem; /* set your desired gap /
grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); / auto-fit as many 80px-min items as will fit, then expand to fill. Replace 80px with your desired width */
/* add this to your btn so you don’t have unexpected misalignments due to some padding or border */
.size-btn {
box-sizing: border-box;
}
Hello,
Thanks for your help earlier. I tried exactly what you suggested switching to Grid, using repeat(auto-fit, minmax(…)), and setting box-sizing: border-box but unfortunately the last column is still slightly misaligned. It ends up a little wider than the rest of the boxes on certain screen widths.
I’ve noticed that the alignment issue happens when there are fewer than 6 items in a row. When there are exactly 6 items, everything aligns perfectly, but when there are less than 6 items, the last column becomes misaligned.
Here’s the exact code I used, based on your recommendation:
Let me know if there’s something I’m missing! I think the issue might be that the 1fr causes the last column to stretch when there’s extra space even though the items look like they’re the same width.
Hello,
Thanks for your insight I completely agree that this is a common issue with responsive grids, especially when using Flexbox or Grid layouts, and the items per row change across breakpoints.
I’ve encountered the same issue, and despite adjusting the grid, the last column becomes misaligned when there are fewer than 6 items per row. I’ve made sure to ensure equal widths, avoid leftover space, and keep proper wrapping/alignment, but the issue persists.
Since you mentioned resolving this with the guidance of someone else, I was wondering if you could share how you managed to fix it? Any advice would be much appreciated!
Thanks again!