小码哥的IT人生

CSS grid-auto-rows 属性 详解

css3基础 2022-07-14 16:28:26小码哥的IT人生shichen

CSS grid-auto-rows 属性

定义和用法

grid-auto-rows 属性为网格容器中的行设置尺寸。

该属性只会影响未设置尺寸的行。

另请参阅:

CSS 教程:CSS 网格布局

CSS 参考手册:grid-auto-columns 属性

实例

设置网格中行的默认尺寸:

.grid-container {
  display: grid;
  grid-auto-rows: 150px;
}

 

完整实例【亲自试一试】:

<!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>
<h1>grid-auto-rows 属性</h1>
<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>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

CSS 语法

grid-auto-rows: auto|max-content|min-content|length;

属性值

描述
auto 默认值。由行中的最大项目的尺寸决定行的尺寸。
max-content 根据行中的最大项目设置每行的尺寸。
min-content 根据行中的最大项目设置每行的尺寸。
length 设置行的尺寸,通过使用合法的长度值。参阅长度单位

技术细节

默认值: auto
继承:
动画制作: 支持。请参阅:动画相关属性
版本: CSS Grid Layout Module Level 1
JavaScript 语法: object.style.gridAutoRows="60px"

浏览器支持

表格中的数字注明了完全支持该属性的首个浏览器版本。

Chrome IE / Edge Firefox Safari Opera
57 16 52 10 44

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024