I have a website that has a grid with multiple items, I decided to use auto-fit to minimize the use of media queries. The code works perfectly but, the problem is that the last row is aligned to the left (because that's how css grid works I know). So I was wondering if anyone know any method to center the elements in the last row. I don't want to use flexbox because doesn't fit what I'm looking for. I'll accept the use of javascript to accomplish it because I'm using it in my website so, why not.
Here's my code:
.music-grid {
min-height: 100vh;
width: 100%;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(20em, 1fr));
grid-auto-rows: max-content;
gap: 2em;
}
This is how the grid looks