Sorry for the delay, but this information is definitely valuable.
Overview.
- Utilization of
%
When using %
to calculate grid columns, it's important to consider gutters (gaps). You must add the pixel values of the gutters to the calculation. For example:
totalGridWidth = SUM(...%) + gutters = ~100% + gutters
- Utilization of
fr
This issue doesn't arise (except in case 3.) because it factors in the free space along with the gaps during calculation. The formula is as follows:
(free space - gutters) / 12 = 1fr
, allowing for ratios to be represented as fractions rather than percentages.
To put it another way, utilizing the Least Common Divisor (LCD = 5%):
grid-template-columns: 3fr 5fr 7fr 5fr;
- Utilization of
minmax(0,Xfr)
Typically, the browser layout engine uses a formula like minmax(auto,Xfr)
to calculate Xfr
. However, if items are expected to grow indefinitely (e.g. with width:100%
), this can lead to overflowing grids. To avoid this, you should use minmax(0,Xfr)
where X is the desired fraction.
In your specific scenario, this would translate to:
grid-template-columns: minmax(0,3fr) minmax(0,5fr) minmax(0,7fr) minmax(0,5fr);
While this explanation may seem lengthy, it's crucial for preventing grid overflow issues in unique cases like yours. Using repeat()
won't suffice, making this method foolproof against potential glitches.
For further insights, I recommend checking out this informative article:
https://css-tricks.com/preventing-a-grid-blowout/