
- 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 - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - 偏移量
- CSS - Accent Color
- CSS - User Select
- 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 - Caret Color
- 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-areas 屬性
CSS grid-template-areas 屬性定義了網格中命名的區域,這些區域概述了單元格的排列並用特定名稱標識它們。然後,網格的元素可以使用這些名稱透過 grid-area 屬性引用特定區域。
語法
grid-template-areas: none | item-names;
屬性值
值 | 描述 |
---|---|
none | 它指定網格佈局中沒有命名區域。 |
item-names | 它是一個包含區域名稱的字串序列,用於指定行和列的大小。 |
CSS 網格模板區域屬性示例
以下示例解釋了具有不同值的 grid-template-areas 屬性。
使用 none 值的網格模板區域屬性
為了在網格佈局中不包含任何命名區域,並且專案以其自然流程顯示,我們使用 none 值。專案的大小取決於其內容。這在以下示例中顯示。
示例
<!DOCTYPE html> <html> <head> <style> .container { display: grid; background-color: lightgrey; grid-gap: 10px; padding: 20px; } .container > div padding: 20px; text-align: center; color: white; border: 3px solid blue; background-color: #4775d1; grid-template-areas: none; </style> </head> <body> <h2> CSS grid-template-areas property </h2> <h4> grid-template-areas: none </h4> <div class="container"> <div> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> <div> Item-4 </div> </div> </body> </html>
使用命名區域的網格模板區域屬性
為了在網格佈局中具有特定的命名區域,我們將包含區域名稱的字串序列指定給 grid-template-areas 屬性。每個單獨的字串序列表示一行,字串中的名稱數量表示列的數量。必須使用 grid-area 屬性來引用該區域。這在以下示例中顯示。
示例
<!DOCTYPE html> <html> <head> <style> .container { display: grid; background-color: lightgrey; grid-gap: 10px; padding: 20px; } .container>div { padding: 20px; text-align: center; color: white; border: 3px solid blue; } .container1 { grid-template: 'header header header header' 'sidebar1 content content sidebar2' 'footer footer footer footer'; } .container2 { grid-template: '. . . .' '. . item item'; } .container2>div { background-color: lightcoral; } .cont1-item1 { background-color: #05445e; grid-area: header; } .cont1-item2 { background-color: #75e6da; grid-area: sidebar1; } .cont1-item3 { background-color: #189ab4; grid-area: content; } .cont1-item4 { background-color: #8bcd50; grid-area: footer; } .cont1-item5 { background-color: #75e6da; grid-area: sidebar2; } .cont2-item1 { grid-area: item; } </style> </head> <body> <h2> CSS grid-template-areas property </h2> <p> <strong> grid-template-areas: 'header header header header' 'sidebar1 content content sidebar2' 'footer footer footer footer' </strong> ; The layout has three rows indicated by three separate strings and four columns indicated by the number of items inside strings ' ' </p> <div class=" container container1"> <div class="cont1-item1"> This is header </div> <div class="cont1-item2"> This is sidebar1 </div> <div class="cont1-item3"> This is content </div> <div class="cont1-item4"> This is footer </div> <div class="cont1-item5"> This is sidebar2 </div> </div> <p> <strong> grid-template-areas: '. . . .''. . item item' </strong> ; the layout has 2 rows and 4 columns, item1 is placed in the second row and takes 2 columns space. </p> <div class=" container container2"> <div class="cont2-item1"> Item-1 </div> <div> Item-2 </div> <div> Item-3 </div> <div> Item-4 </div> <div> Item-5 </div> <div> Item-6 </div> </div> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
grid-template-areas | 57 | 16 | 52 | 10 | 44 |
css_properties_reference.htm
廣告