I have a grid that is populated with elements from a v-for loop in Vue. Also, I have a search bar that reduces grid elements based on the input. If the element count is more than 3 then it looks great, but when I only have left 2 elements it's too spaced out. Therefore, I'd like to change display: grid; to display: flex; if elements in the grid are less than 3.
I've tried with CSS selectors, perhaps I'm doing something wrong since I'm fairly new to programming. I know how to add a dynamic class using javascript, however, I'd like to see if it would be possible with plain CSS.
Tried the following css selector and its variations:
.grid-container {
display: grid;
grid-template-columns: repeat( auto-fit, minmax(290px, 1fr) );
grid-gap: 3rem;
}
.grid-container:first-child:nth-last-child(n + 2) {
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
align-items: auto;
align-content: center;
}