liveBook · Manning

Grid-template-columns

As explained in Tiny CSS Projects

The CSS grid-template-columns property defines the sizes and number of columns in a grid.

Use `grid-template-columns` on a grid container to define how many columns it has and how wide they are. Its value is a space-separated list of column tracks—the spaces between vertical grid lines. Start by setting `display: grid` on the parent element. section 2.3 section 2.7

Two flexible columns and one fixed column

The declaration `grid-template-columns: repeat(2, minmax(auto, 1fr)) 250px;` creates three columns: two equally flexible columns followed by a 250-pixel column. `repeat(2, …)` avoids writing the same track size twice. For the first two columns, `minmax(auto, 1fr)` uses the contained element’s width as a minimum and a fraction of available space as the flexible size. section 2.3.1 section 2.3.3

Think of `fr` values as shares of the space available to flexible tracks. `1fr 1fr 1fr 1fr` gives four columns equal shares; `3fr repeat(3, 1fr)` gives the first column three shares and each remaining column one. Grid distributes leftover space after minimum sizes have been applied. section 2.3.4

Listing 2.4 Setting the amount of columns
main {
  display: grid;
  grid-template-columns: repeat(2, minmax(auto, 1fr)) 250px;
}

See the complete `main` rule with `display: grid` and its three-column track list. section 2.3.4

How Tiny CSS Projects covers it

How deep it goes
Works through track lists, repeated columns, minimum widths, and fractional sizing without detailing browser layout algorithms.
Examples
Uses a three-column `main` layout and equal-versus-unequal `fr` shares to demonstrate track sizing.
What it assumes
Introduces grid tracks and CSS function arguments while using an HTML parent and child elements.
What you can do after
Build it from scratch: define fixed and flexible columns on a CSS Grid container.
How it connects
Connects CSS Grid tracks to `display: grid`, `grid-template-rows`, `repeat()`, `minmax()`, and the `fr` unit.

Also explained in

Compare how 4 books explain grid-template-columns →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.