Although looking deeper into your project I saw that you’re using grid for this. I would recommend changing to flexbox for this if you want an easier way to do it.
I 'm not 100% sure if that’s what you’re looking for, but if you use the Flex Child Grow And Shrink customizable settings, I believe you can achieve what you need. Using code might be faster, and less “thinking-demanding”. But it would be interesting to achieve that without code