Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Grid Item in CSS

Grid Item in CSS

? CSS Grid Item

A Grid Item is any direct child of a CSS Grid Container. These items are placed into the grid cells (the intersection of rows and columns) and can be precisely controlled using various CSS Grid properties.


Key Properties for Grid Items

PropertyDescriptionExample
grid-column-startSpecifies the starting grid column linegrid-column-start: 2;
grid-column-endSpecifies the ending grid column linegrid-column-end: 4;
grid-row-startSpecifies the starting grid row linegrid-row-start: 1;
grid-row-endSpecifies the ending grid row linegrid-row-end: 3;
grid-columnShorthand for grid-column-start / grid-column-endgrid-column: 2 / 4;
grid-rowShorthand for grid-row-start / grid-row-endgrid-row: 1 / 3;
grid-areaAssigns a grid item to a named area or spans linesgrid-area: 1 / 2 / 3 / 4;
justify-selfAligns item horizontally within its grid cellstart, end, center, stretch
align-selfAligns item vertically within its grid cellstart, end, center, stretch

Positioning Grid Items by Lines

You can position a grid item by specifying the grid lines it should start and end on.

.item {  grid-column: 2 / 4; /* spans from column line 2 up to (but not including) 4 */  grid-row: 1 / 3;    /* spans from row line 1 to 3 */}

Example: Grid Item Spanning Multiple Cells

<div class="container">  <div class="item1">Item 1</div>  <div class="item2">Item 2</div>  <div class="item3">Item 3</div></div>
.container {  display: grid;  grid-template-columns: repeat(3, 1fr);  grid-template-rows: 100px 100px;  gap: 10px;}.item2 {  grid-column: 2 / 4; /* spans 2 columns */  grid-row: 1 / 3;    /* spans 2 rows */  background-color: lightcoral;}

Aligning Individual Items

.item1 {  justify-self: center; /* horizontally centers the item */  align-self: end;      /* aligns item to the bottom of its cell */}

Summary

  • Grid Items are direct children of the grid container.

  • Use grid-column and grid-row to position and span items.

  • Use justify-self and align-self to align items inside their grid cells.

  • grid-area is a shorthand or can reference named grid areas.


Want me to show examples with named grid areas or how to combine grid items with responsive layouts?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql