Used in graphic design to guide objects.
In this unit, we will delve into the concepts of Grid Gap and Grid Line in CSS Grid Layout. These are fundamental aspects that contribute to the overall structure and design of a grid layout.
The grid-gap
property is a shorthand for grid-row-gap
and grid-column-gap
, specifying the size of the gap between the rows and columns in a grid.
.container { display: grid; grid-gap: 20px; }
In the above example, the grid-gap
property sets a gap of 20px between all rows and columns in the grid.
The grid-row-gap
property sets the size of the gap between the rows in a grid, while the grid-column-gap
property sets the size of the gap between the columns.
.container { display: grid; grid-row-gap: 20px; grid-column-gap: 10px; }
In this example, the grid-row-gap
property sets a gap of 20px between the rows, and the grid-column-gap
property sets a gap of 10px between the columns.
Grid lines are the dividing lines that make up the structure of the grid. They can be horizontal or vertical ("column grid lines") and reside on either side of a row or column. You can refer to these lines by number when positioning grid items.
.item { grid-column-start: 2; grid-column-end: 4; }
In the above example, the grid item will start from the second vertical grid line and span until the fourth vertical grid line.
Grid lines can also be named, which can make your grid code easier to understand.
.container { display: grid; grid-template-columns: [start] 1fr [middle] 2fr [end]; } .item { grid-column: start / end; }
In this example, the grid lines are named 'start', 'middle', and 'end'. The grid item will start from the 'start' line and span until the 'end' line.
Understanding and effectively using grid-gap
and grid lines are crucial for mastering CSS Grid Layout. They provide the flexibility and control needed to create complex and responsive designs.