grid-template-rows

CSS grid-template-rows Property

The grid-template-rows property defines the number and size of the rows in a grid layout. The values of the grid-template-row property are separated by space. Each of the values specifies the row height.

Besides the main values, there are two other values which are experimental technology: “fit-content” and “repeat”.

类目类目
Initial Valuenone
Applies toGrid containers.
InheritedNo.
AnimatableYes. The size of the rows is animatable.
VersionCSS Grid Layout Module Level 1
DOM Syntaxobject.style.gridTemplateRows = “20px 100px”;

Syntax

Syntax

grid-template-rows: none | auto | max-content | min-content | flex | fit-content| repeat | length | initial | inherit;

Example of the grid-template-row property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .auto-container {
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-template-rows: auto auto;
        grid-gap: 10px;
        background-color: #ccc;
        padding: 10px;
        margin-top: 30px;
      }
      .auto-container > div {
        background-color: #eee;
        text-align: center;
        padding: 30px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-template-rows property example</h2>
    <div class="auto-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
    </div>
  </body>
</html>

Result

Example of the grid-template-row property with the specified size of rows:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grid-container {
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-template-rows: 100px 300px;
        grid-gap: 10px;
        background-color: #ccc;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #eee;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-template-rows property example</h2>
    <div class="grid-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
    </div>
  </body>
</html>

Values

Values

ValueDescriptionPlay it
noneThis is the default value of the property.Play it »
autoThe size of the rows takes up the size of the container.Play it »
max-contentThe size of each rows depends on the largest item in the rows.
min-contentThe size of each rows depends on the smallest item in the rows.
minmax(min.max)The size range is greater than or equal to “min” and less than or equal to “max”.
<length>The size of the rows is specified by length value.Play it »
<percentage>The size of the rows is specified by percentages.
<flex>A non-negative dimension with the unit “fr” that specifies the track’s flex factor. Each <flex>-sized track shares remaining space in proportion to its flex factor.
fit-contentRepresents the min(max-content, max(auto, argument)), which is similar to auto (i.e. minmax(auto, max-content)), but the size is greater than the auto minimum. This value is considered to be experimental.
repeatRepresents a repeated fragment of the track list, allowing a large number of rows that exhibit a recurring pattern to be written in a more compact form.This value is considered to be experimental.
subgridIndicates the grid will adopt the spanned portion of its parent grid in the specified axis. The sizes of the grid rows/columns are taken from the parent grid’s definition.
initialMakes the property use its default value.
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部