CSS Grid Layout Flashcards

1
Q

What CSS property enables Grid layout on an element?

A

display

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does grid-template-columns do?

A

It defines the number and size of the columns in the grid.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens if there are more grid items than defined columns/rows?

A

The grid creates additional implicit rows or columns to fit them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you make an item span two columns?

A

Use grid-column: span 2; or grid-column: 1 / 3;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the shorthand for grid-row and grid-column?

A

grid-area: row-start / column-start / row-end / column-end;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the difference between auto-fill and auto-fit?

A

auto-fill keeps empty tracks; auto-fit collapses them if empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does this CSS do?

grid-template-columns: repeat(3, 1fr);
A

Creates 3 equal-width columns. Creates 3 equal-width columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the default value of justify-items and align-items?

A

stretch — items fill the entire cell by default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does this do?

grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
A

Creates responsive columns that are at least 200px wide and grow to fill available space, wrapping when needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you position an item at column 2, row 3?

A

grid-column: 2; grid-row: 3;
or
grid-area: 3 / 2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you make the center column twice as wide as the others in a 3-column layout?

A

grid-template-columns: 1fr 2fr 1fr;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Does setting margin on a grid item affect gap?

A

No, gap is separate from margins and doesn’t collapse with them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When would you use min-content or max-content in a grid?

A

Use min-content to shrink to the smallest size without overflow; max-content to expand to the largest natural size of the content.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Make a 3-column layout with equal-width columns.

A
.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Make the first item span 2 columns.

A
.item1 {
  grid-column: span 2;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to create columns that are at least 150px wide and auto-wrap?

A
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
17
Q

Imagine there is a grid, how can you place .item3 in the second column and third row.

A
.item3 {
  grid-column: 2;
  grid-row: 3;
}
18
Q

Create a .container grid and nest another grid inside .card.

A
<div class="container">
  <div class="card">
    <h3>Title</h3>
    <p>Content</p>
    <button>Buy</button>
  </div>
</div>
19
Q

Use subgrid to align columns between parent and child.

A
.parent {
  display: grid;
  grid-template-columns: 100px 1fr 1fr;
}
.child {
  display: grid;
  grid-column: 1 / 4;
  grid-template-columns: subgrid;
}
20
Q

Is this a valid declaration?

header {
  grid-area: 1 / 1 / 1 / 3;
}
A

Invalid — row-start equals row-end, so height is 0.