وحدة تخطيط شبكة CSS
رأس
قائمة الطعام
الأساسية
حق
تذييل
تخطيط الشبكة
توفر CSS Grid Layout Module نظام تخطيط قائم على الشبكة ، مع صفوف وأعمدة ، مما يسهل تصميم صفحات الويب دون الحاجة إلى استخدام العوامات وتحديد المواقع.
دعم المتصفح
خصائص الشبكة مدعومة في جميع المتصفحات الحديثة.
57.0 | 16.0 | 52.0 | 10 | 44 |
عناصر الشبكة
يتكون تخطيط الشبكة من عنصر أصلي ، مع عنصر فرعي واحد أو أكثر.
مثال
<div
class="grid-container">
<div class="grid-item">1</div>
<div
class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div
class="grid-item">5</div>
<div class="grid-item">6</div>
<div class="grid-item">7</div>
<div
class="grid-item">8</div>
<div class="grid-item">9</div>
</div>
1
2
3
4
5
6
7
8
9
خاصية العرض
يصبح عنصر HTML حاوية شبكة عند display
تعيين خاصيته على
grid
أو inline-grid
.
مثال
.grid-container {
display: grid;
}
مثال
.grid-container {
display: inline-grid;
}
جميع العناصر الفرعية المباشرة لحاوية الشبكة تصبح عناصر شبكة تلقائيًا .
أعمدة الشبكة
تسمى الخطوط الرأسية لعناصر الشبكة بالأعمدة .
صفوف الشبكة
تسمى الخطوط الأفقية لعناصر الشبكة بالصفوف .
فجوات الشبكة
الفراغات بين كل عمود / صف تسمى فجوات .
يمكنك ضبط حجم الفجوة باستخدام إحدى الخصائص التالية:
grid-column-gap
grid-row-gap
grid-gap
مثال
grid-column-gap
تحدد الخاصية الفجوة بين الأعمدة :
.grid-container {
display: grid;
grid-column-gap: 50px;
}
مثال
تحدد grid-row-gap
الخاصية الفجوة بين الصفوف:
.grid-container {
display: grid;
grid-row-gap: 50px;
}
مثال
الخاصية هي grid-gap
خاصية مختصرة للعقارات
grid-row-gap
و
grid-column-gap
:
.grid-container {
display: grid;
grid-gap: 50px 100px;
}
مثال
يمكن grid-gap
أيضًا استخدام الخاصية لتعيين فجوة الصفوف وفجوة العمود في قيمة واحدة:
.grid-container {
display: grid;
grid-gap: 50px;
}
خطوط الشبكة
تسمى الخطوط بين الأعمدة خطوط الأعمدة .
تسمى الخطوط بين الصفوف خطوط الصف .
الرجوع إلى أرقام الأسطر عند وضع عنصر شبكة في حاوية شبكة:
مثال
ضع عنصر شبكة في سطر العمود 1 ، واتركه ينتهي عند سطر العمود 3:
.item1 {
grid-column-start: 1;
grid-column-end: 3;
}
مثال
ضع عنصر شبكة في السطر 1 ، واتركه ينتهي في سطر الصف 3:
.item1 {
grid-row-start: 1;
grid-row-end: 3;
}
جميع خصائص CSS Grid
Property | Description |
---|---|
column-gap | Specifies the gap between the columns |
gap | A shorthand property for the row-gap and the column-gap properties |
grid | A shorthand property for the grid-template-rows, grid-template-columns, grid-template-areas, grid-auto-rows, grid-auto-columns, and the grid-auto-flow properties |
grid-area | Either specifies a name for the grid item, or this property is a shorthand property for the grid-row-start, grid-column-start, grid-row-end, and grid-column-end properties |
grid-auto-columns | Specifies a default column size |
grid-auto-flow | Specifies how auto-placed items are inserted in the grid |
grid-auto-rows | Specifies a default row size |
grid-column | A shorthand property for the grid-column-start and the grid-column-end properties |
grid-column-end | Specifies where to end the grid item |
grid-column-gap | Specifies the size of the gap between columns |
grid-column-start | Specifies where to start the grid item |
grid-gap | A shorthand property for the grid-row-gap and grid-column-gap properties |
grid-row | A shorthand property for the grid-row-start and the grid-row-end properties |
grid-row-end | Specifies where to end the grid item |
grid-row-gap | Specifies the size of the gap between rows |
grid-row-start | Specifies where to start the grid item |
grid-template | A shorthand property for the grid-template-rows, grid-template-columns and grid-areas properties |
grid-template-areas | Specifies how to display columns and rows, using named grid items |
grid-template-columns | Specifies the size of the columns, and how many columns in a grid layout |
grid-template-rows | Specifies the size of the rows in a grid layout |
row-gap | Specifies the gap between the grid rows |