CSS Tutorial
Grid is a powerful layout system in CSS that provides flexibility and control over how elements are arranged on a web page. It allows you to create complex grid-based layouts with ease.
display: grid
property on the parent element.grid-template-columns
and grid-template-rows
properties.grid-column
and grid-row
properties to position items within the grid.grid-gap
or grid-column-gap
and grid-row-gap
properties to specify the spacing between tracks.grid-template-areas
property to define named regions. Use the grid-area
property on grid items to place them in these areas..grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-gap: 1em;
}
.grid-item {
grid-column: span 2;
grid-row: 2;
background: blue;
}
This example creates a 3-column, 2-row grid with a 1em gap between tracks. The grid item spans 2 columns and is positioned in the second row, resulting in the following layout:
______________________________
| | | |
|-----+-----+-----|
| | | |
|-----+-----+-----|
| |
| |
| |
|____________________________|