Currently, I am delving into grid layouts in CSS and experimenting with code to divide a row. Here is the snippet I am playing around with:
.grid-sample {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
row-gap: 4rem;
padding: 0 5rem;
}
As far as I comprehend, using grid-template-columns: 1fr ...
divides the row into 4 equal columns.
I wonder if there is a way to enhance this code so that it dynamically adjusts based on the number of items present? For instance, when there are only 3 items, can the row automatically split into 3 equal columns instead of grouping them in the first three positions of the 4-column grid?
Your insights will be greatly appreciated!