Definition
The grid
CSS property is a shorthand property that combines several other grid-related properties, including grid-template-rows
, grid-template-columns
, grid-template-areas
, grid-auto-rows
, grid-auto-columns
, grid-auto-flow
, and grid-gap
. It provides a convenient way to define the overall grid structure and properties in a single declaration.
Here’s an example:
.grid-container {
display: grid;
grid-template:
"header header"
"sidebar content"
/ 200px 1fr;
grid-gap: 10px;
}
In this example, the grid
property sets up a grid layout with two rows and two columns. The first row is for the header, the second row is divided into the sidebar and content areas. The columns are defined as 200px
for the first column and the remaining space is divided equally using 1fr
. Additionally, the grid-gap
property sets a gap of 10px
between grid items.
The grid
property simplifies the declaration of grid-related properties, making it easier to define the grid structure, sizes, and gaps. It provides a powerful tool for creating flexible and responsive grid layouts.