คุณสมบัติกริด CSS
ตัวอย่าง
สร้างเค้าโครงตารางสามคอลัมน์โดยที่แถวแรกสูง 150px:
.grid-container {
display: grid;
grid: 150px
/ auto auto auto;
}
ความหมายและการใช้งาน
grid
ทรัพย์สินเป็นทรัพย์สินชวเลขสำหรับ:
- ตารางแม่แบบแถว
- ตารางเทมเพลตคอลัมน์
- ตารางแม่แบบพื้นที่
- ตารางอัตโนมัติแถว
- ตารางอัตโนมัติคอลัมน์
- กริดอัตโนมัติไหล
ค่าเริ่มต้น: | ไม่มี ไม่มี ไม่มี อัตโนมัติ แถวอัตโนมัติ |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ใช่ดูคุณสมบัติแต่ละรายการ อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS Grid Layout Module ระดับ 1 |
ไวยากรณ์ JavaScript: | วัตถุ .style.grid="250px / auto auto auto" |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
grid | 57 | 16 | 52 | 10 | 44 |
ไวยากรณ์ CSS
grid: none|grid-template-rows /
grid-template-columns|grid-template-areas|grid-template-rows
/ [grid-auto-flow] grid-auto-columns|[grid-auto-flow] grid-auto-rows / grid-template-columns|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description | Play it |
---|---|---|
none | Default value. No specific sizing of the columns or rows | |
grid-template-rows / grid-template-columns | Specifies the size(s) of the columns and rows | |
grid-template-areas | Specifies the grid layout using named items | |
grid-template-rows / grid-auto-columns | Specifies the size (height) of the rows, and the auto size of the columns | |
grid-auto-rows / grid-template-columns | Specifies the auto size of the rows, and sets the grid-template-columns property | |
grid-template-rows / grid-auto-flow grid-auto-columns | Specifies the size (height) of the rows, and how to place auto-placed items, and the auto size of the columns | |
grid-auto-flow grid-auto-rows / grid-template-columns | Specifies how to place auto-placed items, and the auto size of the rows, and sets the grid-template-columns property | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ระบุสองแถว โดยที่ "item1" ครอบคลุมสองคอลัมน์แรกในสองแถวแรก (ในรูปแบบตารางห้าคอลัมน์):
.item1 {
grid-area: myArea;
}
.grid-container {
display: grid;
grid:
'myArea myArea . . .'
'myArea myArea . . .';
}
ตัวอย่าง
ตั้งชื่อรายการทั้งหมด และสร้างเทมเพลตหน้าเว็บที่พร้อมใช้งาน:
.item1 { grid-area: header; }
.item2 { grid-area:
menu; }
.item3 { grid-area:
main; }
.item4 { grid-area:
right; }
.item5 { grid-area:
footer; }
.grid-container {
display: grid;
grid:
'header header header header header'
'menu main main main right right'
'menu footer footer
footer footer';
}
หน้าที่เกี่ยวข้อง
บทช่วยสอน CSS: CSS Grid Container
การอ้างอิง CSS: คุณสมบัติgrid -template-areas
การอ้างอิง CSS: คุณสมบัติgrid -template-rows
การอ้างอิง CSS: คุณสมบัติgrid -template-columns
การอ้างอิง CSS: คุณสมบัติgrid -auto-rows
การอ้างอิง CSS: คุณสมบัติgrid -auto-columns
การอ้างอิง CSS: คุณสมบัติgrid -auto-flow
การอ้างอิง CSS: คุณสมบัติgrid -row-gap
การอ้างอิง CSS: คุณสมบัติgrid -column-gap