CSS grid-area Property: Defining Grid Item Size and Position
The 'grid-area' property in CSS is used to define the size and position of a grid item within a CSS grid layout. It acts as a shorthand for combining the 'grid-row-start', 'grid-column-start', 'grid-row-end', and 'grid-column-end' properties into a single value.
The 'grid-area' property accepts four values, in the order of 'grid-row-start', 'grid-column-start', 'grid-row-end', and 'grid-column-end'. These values can be specified as either a number or a named grid line. For instance:
.item {
grid-area: 2 / 1 / 4 / 4;
}
This code snippet defines an item that starts at row 2, column 1 and extends to row 4, column 4 within the grid.
Alternatively, the 'grid-area' property can also accept a name, which references a named grid area defined using the 'grid-template-areas' property. Let's look at an example:
.grid {
display: grid;
grid-template-areas:
'header header header'
'sidebar main main'
'footer footer footer';
}
.item {
grid-area: main;
}
This code defines an item spanning the 'main' grid area, which encompasses cells in rows 2 and 3, along with columns 2 and 3.
AI 优化版
原文地址:https://www.cveoy.top/t/topic/ncT3 著作权归作者所有。请勿转载和采集!