- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 內聯塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - Clearfix
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 定位
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 焦點
- CSS - 縮放
- CSS - 位移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 疊加層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 內嵌
- CSS - 隔離
- CSS - 滾動溢位
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊尺寸
- CSS - 最小塊尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移
- CSS - 重音色
- CSS - 使用者選擇
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - grid-template-rows 屬性
CSS grid-template-rows 屬性用於定義網格佈局中行數和大小。值是用空格分隔的列表。
語法
grid-template-rows: none | auto | max-content | min-content | length | initial | inherit;
屬性值
| 值 | 描述 |
|---|---|
| none | 如果需要,可以建立行。預設值。 |
| auto | 行的大小取決於容器的大小和行中專案內容的大小。 |
| max-content | 使用此值時,每行的尺寸取決於該行中最大專案的尺寸。 |
| min-content | 使用此值時,每行的尺寸取決於該行中最小的專案的尺寸。 |
| length | 行的尺寸以長度單位指定(例如 px、em 等)。 |
CSS 網格模板行屬性示例
以下示例使用不同的值解釋了grid-template-rows 屬性。
使用 none 值的網格模板行屬性
為了不為網格容器定義任何明確的行大小,我們使用none 值。它有效地重置行定義,網格將不使用任何已定義的行結構。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-rows: none;
grid-gap: 10px;
background-color: lightgray;
padding: 10px;
}
.grid-container>div {
border: 3px solid blue;
color: white;
background-color: #4d4dff;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h2>
CSS grid-template-rows property
</h2>
<h4>
grid-template-rows: none
</h4>
<div class="grid-container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
<div>
Item-4
</div>
</div>
</body>
</html>
使用 auto 值的網格模板行屬性
為了允許行根據其內容自動調整大小,我們使用auto 值。每行的高度都足以容納其內容。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto auto;
grid-gap: 10px;
background-color: lightgray;
padding: 10px;
}
.grid-container>div {
border: 3px solid blue;
color: white;
background-color: #4d4dff;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h2>
CSS grid-template-rows property
</h2>
<h4>
grid-template-rows: auto auto auto
(3 rows are created and sizes depend
on the size of container and content of items)
</h4>
<div class="grid-container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
<div>
Item-4
</div>
<div>
Item-5
</div>
<div>
Item-6
</div>
<div>
Item-7
</div>
<div>
Item-8
</div>
<div>
Item-9
</div>
</div>
</body>
</html>
使用 max-content 值的網格模板行屬性
為了使行的高度與其內容所需的一樣高,而沒有任何截斷或換行,我們使用max-content 值。無論網格容器的大小如何,行都將擴充套件以適應其包含的最長內容。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows:
max-content max-content max-content;
grid-gap: 10px;
background-color: lightgray;
padding: 10px;
}
.grid-container>div {
border: 3px solid blue;
color: white;
background-color: #4d4dff;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h2>
CSS grid-template-rows property
</h2>
<h4>
grid-template-rows: max-content
max-content max-content (3 rows are
created and sizes depend on the largest
item in the row)
</h4>
<div class="grid-container">
<div>
This is Item-1
</div>
<div>
2
</div>
<div>
This is Item-3 in row 1
</div>
<div>
Item-4
</div>
<div>
Item-5
</div>
<div>
Item-6
</div>
<div>
Item-7
</div>
<div>
8
</div>
<div>
Item-9
</div>
</div>
</body>
</html>
使用 min-content 值的網格模板行屬性
為了使行儘可能短,同時仍然適合其內容而不會溢位,我們使用min-content 值。行的高度僅需顯示其內容而無需換行,但不會更窄。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows:
min-content min-content min-content;
grid-gap: 10px;
background-color: lightgray;
padding: 10px;
}
.grid-container > div {
border: 3px solid blue;
color: white;
background-color: #4d4dff;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h2>
CSS grid-template-rows property
</h2>
<h4>
grid-template-rows: min-content
min-content min-content (3 rows
are created and sizes depend on the
smallest item in the row)
</h4>
<div class="grid-container">
<div>
Item-1
</div>
<div>
2
</div>
<div>
Item-3
</div>
<div>
4
</div>
<div>
5
</div>
<div>
6
</div>
<div>
Item-7
</div>
<div>
8
</div>
<div>
Item-9
</div>
</div>
</body>
</html>
使用長度值的網格模板行屬性
可以使用長度值(例如 px、em、rem 等)設定行數和大小。根據提供的值,將建立具有指定寬度的行數。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container{
display: grid;
grid-gap: 10px;
background-color: lightgray;
padding: 10px;
grid-template-columns: auto auto auto;
}
.grid-container1 {
grid-template-rows: 140px 200px 140px;
}
.grid-container2{
grid-template-rows: 10em 7em 10em;
}
.container > div {
border: 3px solid blue;
color: white;
background-color: #4d4dff;
text-align: center;
padding: 20px;
}
.
</style>
</head>
<body>
<h2>
CSS grid-template-rows property
</h2>
<h4>
grid-template-rows: 150px 200px 150px
(3 rows are created and sizes are 150px,
200px and 150px respectively)
</h4>
<div class=" container grid-container1">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
<div>
Item-4
</div>
<div>
Item-5
</div>
<div>
Item-6
</div>
<div>
Item-7
</div>
<div>
Item-8
</div>
<div>
Item-9
</div>
</div>
<h4>
grid-template-rows: 10em 7em 10em
(3 rows are created and sizes are
10em, 7em and 10em respectively)
</h4>
<div class="container grid-container2">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
<div>
Item-4
</div>
<div>
Item-5
</div>
<div>
Item-6
</div>
<div>
Item-7
</div>
<div>
Item-8
</div>
<div>
Item-9
</div>
</div>
</body>
</html>
使用百分比值的網格模板行屬性
可以使用百分比值(例如 10%、20%)設定行數和大小。根據提供的值,將建立具有指定寬度的行數。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
height: 400px;
grid-gap: 10px;
background-color: lightgray;
padding: 10px;
grid-template-columns: auto auto auto;
grid-template-rows: 25% 15% 25%;
}
.grid-container>div {
border: 3px solid blue;
color: white;
background-color: #4d4dff;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h2>
CSS grid-template-rows property
</h2>
<h4>
grid-template-rows: 25% 15% 25%
(3 rows are created and sizes are 25%,
15% and 25% of the size of the container's
width respectively)
</h4>
<div class="grid-container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
<div>
Item-4
</div>
<div>
Item-5
</div>
<div>
Item-6
</div>
<div>
Item-7
</div>
<div>
Item-8
</div>
<div>
Item-9
</div>
</div>
</body>
</html>
支援的瀏覽器
| 屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| grid-template-rows | 57 | 16 | 52 | 10 | 44 |
css_properties_reference.htm
廣告




