grid-template-columns vs grid-auto-columns

Hey, what would be the difference between the examples below? Other than the ability to define a specific number of columns and how the elements fill the container when using grid-template-columns, when using auto-fill or auto-fit these both seem like they would achieve the same thing to me? Any explanation would be appreciated, Thanks in advance.
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
grid-auto-columns: minmax(16rem, 1fr);
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
grid-auto-columns: minmax(16rem, 1fr);
7 Replies
MarkBoots
MarkBoots6mo ago
- the first will wrap to a new row if there is no space. - the second just sets a default for a column. (could be usefull if you have set grid-auto-flow: column for a horizontal scroll p.e.)
JJ
JJ6mo ago
auto-fit sort of works like flex wrap. If there is enough room for the size of the elements to fit in one row then it will fit all that it can. Otherwise if it cant fit all elements with the specified size that u give it the elements will wrap to a new line.
JJ
JJ6mo ago
Sara Soueidan
CSS-Tricks
Auto-Sizing Columns in CSS Grid: auto-fill vs auto-fit | CSS-Tr...
One of the most powerful and convenient CSS Grid features is that, in addition to explicit column sizing, we have the option to repeat-to-fill columns in a
JJ
JJ6mo ago
goes more in detail in this article while auto fill will create implicit columns meaning at a certain viewport width there will be extra columns created that u did not want
snxxwyy
snxxwyyOP6mo ago
ah thank you, so grid-auto-columns will overflow the container? ah i see, thanks for the link, i'll check it out
JJ
JJ6mo ago
well all grid-auto-columns and grid- auto-rows do is create the sizing for any implicit grid item that is created. So for example if ur entire grid container is full and u want to add another element to that grid the grid will make a new row even though it wasnt stated. when that new row or column is created the size is NOT the the same as the other columns. so u have to give it a size.
snxxwyy
snxxwyyOP6mo ago
oh i see i see, thanks
Want results from more Discord servers?
Add your server