CSS-Eigenschaft grid-auto-rows
Die Eigenschaft grid-auto-rows legt die Größe der Zeilen in einem Grid-Container fest. Sie wirkt sich nur auf Zeilen ohne festgelegte Größe aus.
Diese Eigenschaft hat die folgenden Werte: auto, max-content, min-content, minmax, length und percentages.
| Initial Value | auto |
|---|---|
| Applies to | Grid containers. |
| Inherited | No. |
| Animatable | Yes. Size of the rows is animatable. |
| Version | CSS Grid Layout Module Level 1 |
| DOM Syntax | object.style.gridAutoRows = "40px"; |
Syntax
Syntax der CSS-Eigenschaft grid-auto-rows
css
grid-auto-rows: auto | max-content | min-content | <length> | <percentage> | <flex> | initial | inherit;Beispiel für die Eigenschaft grid-auto-rows:
Beispiel der CSS-Eigenschaft grid-auto-rows mit auto- und length-Werten
html
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.box1 {
grid-area: 1 / 1 / 2 / 2;
}
.box2 {
grid-area: 1 / 2 / 2 / 3;
}
.box3 {
grid-area: 1 / 3 / 2 / 4;
}
.box4 {
grid-area: 2 / 1 / 3 / 2;
}
.box5 {
grid-area: 2 / 2 / 3 / 3;
}
.box6 {
grid-area: 2 / 3 / 3 / 4;
}
.auto-box1 {
grid-area: 1 / 1 / 2 / 2;
}
.auto-box2 {
grid-area: 1 / 2 / 2 / 3;
}
.auto-box3 {
grid-area: 1 / 3 / 2 / 4;
}
.auto-box4 {
grid-area: 2 / 1 / 3 / 2;
}
.auto-box5 {
grid-area: 2 / 2 / 3 / 3;
}
.auto-box6 {
grid-area: 2 / 3 / 3 / 4;
}
.grid-container {
display: grid;
grid-auto-rows: 100px;
gap: 10px;
background-color: #ccc;
padding: 10px;
}
.grid-container > div {
background-color: #666;
text-align: center;
padding: 20px 0;
font-size: 20px;
}
.auto-container {
display: grid;
grid-auto-rows: auto;
gap: 10px;
background-color: #ccc;
padding: 10px;
}
.auto-container > div {
background-color: #666;
text-align: center;
padding: 20px 0;
font-size: 20px;
}
</style>
</head>
<body>
<h2>Grid-auto-rows property example</h2>
<h3>100 pixels</h3>
<div class="grid-container">
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
<div class="box5">5</div>
<div class="box6">6</div>
</div>
<h3>auto</h3>
<div class="auto-container">
<div class="auto-box1">1</div>
<div class="auto-box2">2</div>
<div class="auto-box3">3</div>
<div class="auto-box4">4</div>
<div class="auto-box5">5</div>
<div class="auto-box6">6</div>
</div>
</body>
</html>Ergebnis

Beispiel für die Eigenschaft grid-auto-rows mit mehreren Werten:
Beispiel der CSS-Eigenschaft grid-auto-rows mit auto-, length-, min-content-, percentage- und min-content-Werten
html
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.box1 {
grid-area: 1 / 1 / 2 / 2;
}
.box2 {
grid-area: 1 / 2 / 2 / 3;
}
.box3 {
grid-area: 1 / 3 / 2 / 4;
}
.box4 {
grid-area: 2 / 1 / 3 / 2;
}
.box5 {
grid-area: 2 / 2 / 3 / 3;
}
.box6 {
grid-area: 2 / 3 / 3 / 4;
}
.grey-box1 {
grid-area: 1 / 1 / 2 / 2;
}
.grey-box2 {
grid-area: 1 / 2 / 2 / 3;
}
.grey-box3 {
grid-area: 1 / 3 / 2 / 4;
}
.grey-box4 {
grid-area: 2 / 1 / 3 / 2;
}
.grey-box5 {
grid-area: 2 / 2 / 3 / 3;
}
.grey-box6 {
grid-area: 2 / 3 / 3 / 4;
}
.auto-box1 {
grid-area: 1 / 1 / 2 / 2;
}
.auto-box2 {
grid-area: 1 / 2 / 2 / 3;
}
.auto-box3 {
grid-area: 1 / 3 / 2 / 4;
}
.auto-box4 {
grid-area: 2 / 1 / 3 / 2;
}
.auto-box5 {
grid-area: 2 / 2 / 3 / 3;
}
.auto-box6 {
grid-area: 2 / 3 / 3 / 4;
}
.min-box1 {
grid-area: 1 / 1 / 2 / 2;
}
.min-box2 {
grid-area: 1 / 2 / 2 / 3;
}
.min-box3 {
grid-area: 1 / 3 / 2 / 4;
}
.min-box4 {
grid-area: 2 / 1 / 3 / 2;
}
.min-box5 {
grid-area: 2 / 2 / 3 / 3;
}
.min-box6 {
grid-area: 2 / 3 / 3 / 4;
}
.max-box1 {
grid-area: 1 / 1 / 2 / 2;
}
.max-box2 {
grid-area: 1 / 2 / 2 / 3;
}
.max-box3 {
grid-area: 1 / 3 / 2 / 4;
}
.max-box4 {
grid-area: 2 / 1 / 3 / 2;
}
.max-box5 {
grid-area: 2 / 2 / 3 / 3;
}
.max-box6 {
grid-area: 2 / 3 / 3 / 4;
}
.grid-container {
display: grid;
grid-auto-rows: 150px;
gap: 10px;
background-color: #ccc;
padding: 10px;
}
.grid-container > div {
background-color: #888;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.grey-container {
display: grid;
grid-auto-rows: 30%;
gap: 10px;
background-color: #ccc;
padding: 10px;
}
.grey-container > div {
background-color: #888;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.auto-container {
display: grid;
grid-auto-rows: auto;
gap: 10px;
background-color: #ccc;
padding: 10px;
}
.auto-container > div {
background-color: #888;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.min-container {
display: grid;
grid-auto-rows: min-content;
gap: 10px;
background-color: #000;
padding: 10px;
}
.min-container > div {
background-color: #ccc;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
.max-container {
display: grid;
grid-auto-rows: max-content;
gap: 10px;
background-color: #000;
padding: 10px;
}
.max-container > div {
background-color: #ccc;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Grid-auto-rows property example</h2>
<p>Use the <strong>grid-auto-rows</strong> property to set a default size (height) for all rows.</p>
<h3>150 pixels</h3>
<div class="grid-container">
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
<div class="box5">5</div>
<div class="box6">6</div>
</div>
<h3>30%</h3>
<div class="grey-container">
<div class="grey-box1">1</div>
<div class="grey-box2">2</div>
<div class="grey-box3">3</div>
<div class="grey-box4">4</div>
<div class="grey-box5">5</div>
<div class="grey-box6">6</div>
</div>
<h3>auto</h3>
<div class="auto-container">
<div class="auto-box1">1</div>
<div class="auto-box2">2</div>
<div class="auto-box3">3</div>
<div class="auto-box4">4</div>
<div class="auto-box5">5</div>
<div class="auto-box6">6</div>
</div>
<h3>min-content</h3>
<div class="min-container">
<div class="min-box1">1</div>
<div class="min-box2">2</div>
<div class="min-box3">3</div>
<div class="min-box4">4</div>
<div class="min-box5">5</div>
<div class="min-box6">6</div>
</div>
<h3>max-content</h3>
<div class="max-container">
<div class="max-box1">1</div>
<div class="max-box2">2</div>
<div class="max-box3">3</div>
<div class="max-box4">4</div>
<div class="max-box5">5</div>
<div class="max-box6">6</div>
</div>
</body>
</html>Beispiel für die Eigenschaft grid-auto-rows mit dem Wert "minmax":
>Beispiel für die Eigenschaft grid-auto-rows mit den Werten "minmax":
html
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.box1 {
grid-area: 1 / 1 / 2 / 2;
}
.box2 {
grid-area: 1 / 2 / 2 / 3;
}
.box3 {
grid-area: 1 / 3 / 2 / 4;
}
.box4 {
grid-area: 2 / 1 / 3 / 2;
}
.box5 {
grid-area: 2 / 2 / 3 / 3;
}
.box6 {
grid-area: 2 / 3 / 3 / 4;
}
.minmax1 {
grid-area: 1 / 1 / 2 / 2;
}
.minmax2 {
grid-area: 1 / 2 / 2 / 3;
}
.minmax3 {
grid-area: 1 / 3 / 2 / 4;
}
.minmax4 {
grid-area: 2 / 1 / 3 / 2;
}
.minmax5 {
grid-area: 2 / 2 / 3 / 3;
}
.minmax6 {
grid-area: 2 / 3 / 3 / 4;
}
.grid-container {
display: grid;
grid-auto-rows: 100px;
gap: 10px;
background-color: #ccc;
padding: 10px;
}
.grid-container > div {
background-color: #666;
text-align: center;
padding: 20px 0;
font-size: 20px;
}
.minmax-container {
display: grid;
grid-auto-rows: minmax(90px, 4cm);
gap: 10px;
background-color: #cccccc;
padding: 10px;
}
.minmax-container > div {
background-color: #f5f5f5;
text-align: center;
padding: 20px 0;
font-size: 20px;
}
</style>
</head>
<body>
<h2>Grid-auto-rows property example</h2>
<h3>100 pixels</h3>
<div class="grid-container">
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
<div class="box5">5</div>
<div class="box6">6</div>
</div>
<h3>minmax</h3>
<div class="minmax-container">
<div class="minmax1">1</div>
<div class="minmax2">2</div>
<div class="minmax3">3</div>
<div class="minmax4">4</div>
<div class="minmax5">5</div>
<div class="minmax6">6</div>
</div>
</body>
</html>Hier wird grid-auto-rows verwendet, um eine Standardgröße (Höhe) für alle Zeilen festzulegen.
Werte
| Value | Description | Play it |
|---|---|---|
| auto | Die Größe jeder Zeile wird durch ihren Inhalt bestimmt. Dies ist der Standardwert der Eigenschaft. | Play it » |
| max-content | Die Größe jeder Zeile hängt vom größten Element in der Zeile ab. | Play it » |
| min-content | Die Größe jeder Zeile hängt vom kleinsten Element in der Zeile ab. | Play it » |
| minmax(min, max) | Der Größenbereich ist größer oder gleich "min" und kleiner oder gleich "max". | Play it » |
<length> | Die Größe der Zeilen wird durch einen Längenwert angegeben. | Play it » |
<percentage> | Die Größe der Zeilen wird durch Prozentsätze angegeben. | Play it » |
<flex> | Eine nicht negative Dimension mit der Einheit "fr", die den Flex-Faktor der Spur angibt. Jede Spur mit <flex>-Größe teilt sich den verbleibenden Platz proportional zu ihrem Flex-Faktor. | |
| initial | Verwendet den Standardwert der Eigenschaft. | |
| inherit | Erbt die Eigenschaft vom übergeordneten Element. |
Practice
What is the function of the 'grid-auto-rows' property in CSS grid layout?