Complete the code to add space between grid items using the correct property.
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
[1]: 1rem;
}The gap property adds space between grid items in CSS Grid layouts. It is the modern and recommended way to set gaps.
Complete the code to set a vertical gap of 2rem between grid rows.
.container {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: [1] 1rem;
}The gap property can take two values: the first is the row gap (vertical), the second is the column gap (horizontal). Here, 2rem sets vertical spacing.
Fix the error in the code to correctly add a 10px gap between grid items.
.grid-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
[1]: 10px;
}The correct modern property to set gaps in CSS Grid is gap. Older grid-gap is deprecated, and the others are invalid.
Fill both blanks to create a grid with 3 columns and a 1.5rem gap between rows and 2rem gap between columns.
.container {
display: grid;
grid-template-columns: repeat([1], 1fr);
gap: [2] 2rem;
}The repeat(3, 1fr) creates 3 equal columns. The gap property sets 1.5rem vertical and 2rem horizontal spacing.
Fill all three blanks to create a grid with 4 columns, a 2rem row gap, and a 1rem column gap.
.grid-wrapper {
display: grid;
grid-template-columns: repeat([1], 1fr);
gap: [2] [3];
}This code sets 4 equal columns with repeat(4, 1fr). The gap property sets 2rem vertical and 1rem horizontal spacing.