-
Hajipur, Bihar, 844101
A Grid Item is a direct child of a grid container (display: grid
or inline-grid
). Grid items can be individually placed, sized, and aligned using various CSS properties such as grid-column
, grid-row
, justify-self
, align-self
, and grid-area
.
Grid Container: The parent with display: grid;
Grid Items: The immediate children inside the grid container
Example:
<div class="grid-container">
<div class="item">Item 1</div> <!-- Grid Item -->
<div class="item">Item 2</div> <!-- Grid Item -->
</div>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
}
Property | Description |
---|---|
grid-column-start |
Defines the column line where the item starts |
grid-column-end |
Defines the column line where the item ends |
grid-column |
Shorthand for start/end → e.g., grid-column: 1 / 3 |
grid-row-start |
Defines the row line where the item starts |
grid-row-end |
Defines the row line where the item ends |
grid-row |
Shorthand for start/end → e.g., grid-row: 2 / span 2 |
grid-area |
Assigns item to a named area or custom grid line |
justify-self |
Aligns item horizontally inside its cell |
align-self |
Aligns item vertically inside its cell |
.item1 {
grid-column: 1 / 3; /* spans columns 1 to 2 */
grid-row: 1 / 2; /* stays in row 1 */
}
justify-self
and align-self
.item2 {
justify-self: center;
align-self: end;
}
This centers the item horizontally and aligns it at the bottom of its grid cell.
✅ Write CSS for the following:
Q1. Span one item across 2 columns.
Q2. Span one item across 2 rows.
Q3. Place an item in row 2, column 3.
Q4. Center a specific item inside its cell.
Q5. Align an item to the bottom of its cell.
Q6. Use grid-column: 2 / span 2
.
Q7. Name a grid area and assign an item to it.
Q8. Set different alignments for two items using justify-self
.
Q9. Place a grid item at column 1, row 1 explicitly.
Q10. Make an item take full width but fixed height.
Q1: What is a Grid Item in CSS Grid?
Q2: What does grid-column: 1 / 4; mean?
Q3: Which property aligns an item horizontally inside its cell?
Q4: Which property makes a grid item span 2 rows?
Q5: Which value stretches a grid item in its cell?
Q6: What does grid-column: 2 / -1; do?
Q7: What is required for grid-area: header; to work?
Q8: Which is correct to place an item in row 2 and column 3?
Q9: What does grid-column: 1 / span 2; do?
Q10: Which property allows vertical alignment of individual grid items?