🔹 CSS Grid Placement – How to Place Items Inside a Grid
1. Important Grid Terms
-
Grid Container → The parent div where the entire grid is created.
-
Grid Items → The child elements inside the grid container.
-
Tracks → Row tracks and column tracks that form the rows and columns.
-
Grid Cell → The intersection of a row and a column (the smallest unit of the grid).
-
Grid Lines → The lines that separate tracks. You can use the
gapproperty to create spacing between them, but you cannot add colors or content directly to grid lines.
👉 Together, these build the entire grid structure.
2. Setting Up a Grid Layout
-
First, set the container to:
-
To make the container cover the full screen height:
-
To create columns:
👉 The first 2 columns will be equal, and the 3rd column will be slightly larger.
-
To create rows:
👉 This makes 2 equal rows.
-
To add spacing between rows and columns:
👉 By default, grid items are placed one by one into the cells → first item in cell1, second in cell2, and so on.
3. Centering Content with Flexbox
To center content inside a grid item both horizontally and vertically, you can use Flexbox:
👉 Using Grid + Flexbox together makes layout design much easier.
4. Spanning Grid Items
-
To make an item cover multiple columns:
-
To make an item cover multiple rows:
5. Positioning with Grid Line Numbers
When you highlight a grid in Chrome DevTools, you’ll see line numbers:
-
Positive numbers → Count from the left (1, 2, 3, …)
-
Negative numbers → Count from the right (-1 means the last line).
Example:
👉 This means the item will start at column line 2 and end at column line 4.
6. Order Property (Similar to Flexbox)
-
Each grid item has a default
order: 0. -
If you set a higher order, the item will move further down or to the right.
👉 It works relatively:
-
order: 1→ comes afterorder: 0 -
order: 5→ comes afterorder: 2, etc.
7. Grid Area (Shorthand)
You can control the full placement of an item with grid-area shorthand:
Example:
👉 This means the item starts at row 2 and ends at row 3, starts at column 1 and ends at column 3.
8. Overlapping Items
One of the coolest features of CSS Grid is overlapping items.
👉 This makes the .book div overlap on top of other grid items.
9. Practice – Grid Garden 🎮
Just like Flexbox Froggy, there’s a fun game for CSS Grid → Grid Garden.
👉 Play here
It has 28 levels that help you practice CSS Grid in a fun, interactive way.
✅ Summary
-
Grid Container → Parent div
-
Grid Items → Child divs
-
Tracks = Rows + Columns
-
Cells = Smallest units
-
Lines = Boundaries between tracks
-
grid-column / grid-row → Span items across multiple cells
-
grid-area → Full positioning control in one shorthand
-
order → Change the default flow of items
-
overlap → Place one item on top of another
✨ With these concepts, you can create complex and responsive grid layouts easily.

Comments
Post a Comment