CSS Grid Template Rows
The grid-template-rows property is a fundamental part of CSS Grid Layout. It defines the line names and track sizing functions of the grid rows. Essentially, it controls the vertical size of your grid items.
Defining Track Sizes
You can define the height of your rows using various units:
- Pixels (px): For fixed, absolute heights.
- Percentages (%): Relative to the grid container's height.
- Fraction (fr): Represents a fraction of the available space in the grid container.
- Auto: Sizes the track based on the content.
The fr Unit
The fr unit is unique to CSS Grid. It allows you to distribute available space proportionally. For example, grid-template-rows: 1fr 2fr; will create two rows, where the second row is twice as tall as the first, taking up remaining space.
The repeat() Function
When you have multiple rows of the same size, typing them out manually can be tedious. The repeat() function simplifies this. repeat(3, 1fr) is equivalent to writing 1fr 1fr 1fr.
