Set the gap between rows and between columns to 50px:
.grid-container {
gap: 50px;
}
Try it Yourself »
The gap
property defines the size of the gap between the rows and between the columns in flexbox, grid or multi-column layout. It is a shorthand for the following properties:
Note: The gap
property was formerly known as grid-gap
.
Default value: | normal normal |
---|---|
Inherited: | no |
Animatable: | yes. Read about animatable Try it |
Version: | CSS Box Alignment Module Level 3 |
JavaScript syntax: | object.style.gap="50px 100px" Try it |
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
gap (in Grid) | 66 | 16 | 61 | 12 | 53 |
gap (in Flexbox) | 84 | 84 | 63 | 14.1 | 70 |
gap (in Multiple Columns) | 66 | 16 | 61 | Not supported | 53 |
gap:
row-gap column-gap|initial|inherit;
Value | Description | Demo |
---|---|---|
row-gap | Sets the size of the gap between the rows in a grid or flexbox layout | Demo ❯ |
column-gap | Sets the size of the gap between the columns in a grid, flexbox or multi-column layout | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Set the gap between rows to 20px, and the columns to 50px in a grid layout:
#grid-container {
display: grid;
gap: 20px 50px;
}
Try it Yourself »
Set the gap between rows to 20px, and the columns to 70px in a flexbox layout:
#flex-container {
display: flex;
gap: 20px 70px;
}
Try it Yourself »
Set the gap between the columns to 50px in a multi-column layout:
#newspaper {
columns: 3;
gap: 50px;
}
Try it Yourself »
CSS Tutorial: CSS Grid Layout
CSS Tutorial: CSS Flexbox Layout
CSS Tutorial: CSS Muilti-column Layout
CSS Reference: row-gap property
CSS Reference: column-gap property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!