CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Grid Template Rows


The grid-template-rows property specifies the number and height of the rows in a grid container. It works in the same way as grid-template-columns but for the vertical axis.


Example 1: Using Pixels

/* Defines a grid with two rows of fixed height */
.grid-container {
  display: grid;
  /* The first row is 100px high, and the second is 200px high */
  grid-template-rows: 100px 200px;
}

Explanation This sets up a grid with two rows having explicit heights. This is useful for design elements that require a specific vertical size.


Example 2: Using Percentages

/* Defines responsive row heights */
.grid-container {
  display: grid;
  height: 400px; /* A container height is needed for row percentages to work */
  /* The first row takes 25% and the second 75% of the container's height */
  grid-template-rows: 25% 75%;
}

Explanation When using percentages for grid-template-rows, the grid container must have a defined height. The row heights will then be a percentage of this container height.


Example 3: Using Fractional Units (fr)

/* Defines flexible row heights */
.grid-container {
  display: grid;
  height: 300px;
  /* The first row is twice the height of the second row */
  grid-template-rows: 2fr 1fr;
}

Explanation The fr unit distributes the available vertical space within the grid container among the rows. This allows rows to grow and shrink proportionally.


Example 4: Using the repeat() function

/* Defines three rows of equal height */
.grid-container {
  display: grid;
  height: 600px;
  /* Creates three rows, each 200px high */
  grid-template-rows: repeat(3, 200px);
}

Explanation The repeat() function simplifies the creation of multiple rows with a uniform height, making the CSS cleaner and easier to read.


Example 5: Using minmax()

/* Defines a row with a minimum and maximum height */
.grid-container {
  display: grid;
  /* The row will have a minimum height of 50px and a maximum of auto */
  grid-template-rows: minmax(50px, auto);
}

Explanation minmax() for rows ensures that a row will never be smaller than the minimum value, but can grow to accommodate its content, up to the maximum value specified.


Example 6: Using the auto keyword

/* Defines row heights based on content */
.grid-container {
  display: grid;
  /* The first and third rows are fixed, the middle adapts to its content's height */
  grid-template-rows: 50px auto 100px;
}

Explanation Using auto for row height makes the row as tall as necessary to fit its content. This is ideal for dynamic content of varying lengths.


Example 7: Mixing Units

/* Defines a complex row structure with mixed units */
.grid-container {
  display: grid;
  height: 500px;
  /* A combination of fixed, flexible, and content-based row heights */
  grid-template-rows: 100px 1fr auto;
}

Explanation Combining different units for grid-template-rows provides ultimate control over the vertical rhythm and structure of your grid, creating truly custom layouts.