{"id":366713,"date":"2022-07-15T06:16:58","date_gmt":"2022-07-15T13:16:58","guid":{"rendered":"https:\/\/css-tricks.com\/?page_id=366713"},"modified":"2022-07-15T06:16:59","modified_gmt":"2022-07-15T13:16:59","slug":"grid-auto-columns","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/g\/grid-auto-columns\/","title":{"rendered":"grid-auto-columns"},"content":{"rendered":"\n
The That example creates a grid container with three columns defined by As said above, Here are some situations where that might come up.<\/p>\n\n\n The first case is the one that we saw at the top of this article. A grid can have an explicit column defined by The first column is set to grid-auto-columns<\/code> CSS property is part of the CSS Grid Layout specification<\/a>, specifying the size of the grid columns that were created without having an explicit size. In other words, this property sets the size of implicit columns<\/a> and any other columns that have not been explicitly sized in the
grid-template-columns<\/code><\/a> property.<\/p>\n\n\n\n\n\n\n\n
.grid-container {\n display: grid;\n grid-template-areas: \"media detail detail\";\n grid-template-columns: 200px 400px;\n grid-auto-columns: 150px;\n}<\/code><\/pre>\n\n\n\n
grid-template-areas<\/code>. The first two columns have an explicit size set by
grid-template-columns<\/code>, but not the last column. This is where
grid-auto-columns<\/code> kicks in and sets that column\u2019s size to
150px<\/code>.<\/p>\n\n\n
grid-auto-columns<\/code> use cases<\/h3>\n\n\n
grid-auto-columns<\/code> sets the size of any columns that don\u2019t have an explicit size. Now the question is, what kind of columns don\u2019t have an explicit size? Or, how does a grid create columns without an explicit size?<\/p>\n\n\n\n
Columns that are defined by
grid-template-areas<\/code> that have no explicit size set by
grid-template-columns<\/code><\/h4>\n\n\n
grid-template-areas<\/code> without having its size set explicitly by the
grid-template-columns<\/code> property.<\/p>\n\n\n\n
.grid-container {\n display: grid;\n grid-template-areas: \"media detail detail\"; \/* 3 columns *\/\n grid-template-columns: 200px 150px; \/* 2 sizes *\/\n}<\/code><\/pre>\n\n\n\n
200px<\/code> and the second one has its size set to
150px<\/code>. And since the last column is not set to any explicit size, it will be set to
auto<\/code> and take up the available space that\u2019s leftover from the other two columns.<\/p>\n\n\n\n