CSS grid-auto-rows 属性
CSS grid-auto-rows 属性为网格容器中的行设置尺寸。
实例
设置网格中行的默认尺寸:
<!DOCTYPE html><html><head><style>.item1 { grid-area: 1 / 1 / 2 / 2; }.item2 { grid-area: 1 / 2 / 2 / 3; }.item3 { grid-area: 1 / 3 / 2 / 4; }.item4 { grid-area: 2 / 1 / 3 / 2; }.item5 { grid-area: 2 / 2 / 3 / 3; }.item6 { grid-area: 2 / 3 / 3 / 4; }.grid-container {display: grid;grid-auto-rows: 150px;grid-gap: 10px;background-color: #2196F3;padding: 10px;}.grid-container > div {background-color: rgba(255, 255, 255, 0.8);text-align: center;padding: 20px 0;font-size: 30px;}</style></head><body><h2>grid-auto-rows 属性</h2><p>请使用 <em>grid-auto-rows</em> 属性为所有行设置默认尺寸(高度)。</p><p>把每行的尺寸设置为 150 像素:</p><div class="grid-container"><div class="item1">1</div><div class="item2">2</div><div class="item3">3</div><div class="item4">4</div><div class="item5">5</div><div class="item6">6</div></div><p><b>注释:</b>grid-template-rows 属性覆盖此属性。</p></body></html>
定义和用法
grid-auto-rows 属性为网格容器中的行设置尺寸。
该属性只会影响未设置尺寸的行。
| 默认值: | auto |
|---|---|
| 继承: | 否 |
| 动画制作: | 支持。请参阅:动画相关属性。 |
| 版本: | CSS Grid Layout Module Level 1 |
| JavaScript 语法: | object.style.gridAutoRows="60px" |
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 属性 | |||||
|---|---|---|---|---|---|
| grid-auto-rows | 57 | 16 | 52 | 10 | 44 |
CSS 语法
grid-auto-rows: auto|max-content|min-content|length;
属性值
| 值 | 描述 |
|---|---|
| auto | 默认值。由行中的最大项目的尺寸决定行的尺寸。 |
| max-content | 根据行中的最大项目设置每行的尺寸。 |
| min-content | 根据行中的最大项目设置每行的尺寸。 |
| length | 设置行的尺寸,通过使用合法的长度值。参阅长度单位。 |
相关页面
CSS 教程:CSS 网格布局
CSS 参考手册:grid-auto-columns 属性