Grid Flashcards

1
Q

What is Grid mostly useful for?

A

Whereas Flexbox is mostly useful for positioning items in a one-dimensional layout, CSS grid is most useful for two-dimensional layouts, providing many tools for aligning and moving elements across both rows and columns.

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

Grid Container and Grid Items

A

The grid container will be a parent element that contains grid items as children and applies overarching styling and positioning to them.

display: grid; will create your grid container

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

grid-template-columns: 100px 200px;

and grid-template-rows

A

This property creates two changes.
First, it defines the number of columns in the grid; in this case, there are two.
Second, it sets the width of each column. The first column will be 100 pixels wide and the second column will be 200 pixels wide.

We can also define the size of our columns as a percentage of the entire grid’s width

.grid {
  display: grid;
  width: 1000px;
  grid-template-columns: 20% 50%;
}

grid-template-rows works the same, just with rows

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

grid-template: 200px 300px / 20% 10% 70%;

A

When using grid-template, the values before the slash will determine the size of each row. The values after the slash determine the size of each column. In this example, we’ve made two rows and three columns of varying sizes.

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

fr relative unit

A

The CSS grid relative sizing unit fr is used to split rows and/or columns into proportional distances. Each fr unit is a fraction of the grid’s overall length and width. If a fixed unit is used along with fr (like pixels for example), then the fr units will only be proportional to the distance left over.

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

repeat function

A

A shortcut for specifying grid-template-columns and grid-template-rows

repeat(3, 1fr) would create three 1fr rows/columns

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

minmax() Function

A

The CSS Grid minmax() function accepts two parameters:

The first parameter is the minimum size of a row or column.
The second parameter is the maximum size.
The grid must have a variable width for the minmax() function.

The function can be used in the values of the grid-template-rows, grid-template-columns and grid-template properties.

grid-template-columns: 100px minmax(100px, 500px) 100px;

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

grid-row-gap

A

The CSS grid-row-gap property determines the amount of blank space between each row in a CSS grid layout or in other words, sets the size of the gap (gutter) between an element’s grid rows.

The grid-column-gap provides the same functionality for space between grid columns.

they do not add space at the beginning or end of the grid.

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

grid-row-start and grid-row-end

A

These properties can be used to make grid items take up multiple rows

grid-column-start and grid-column end do the same thing for columns

grid-row-start: 1;
grid-row-end: 3;

will take up the first two rows

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

grid-row: 5 / 7

grid-column: 5 / 7

A

Both are shorthand for the grid-row-start / grid-row-end and grid-column-start / grid-column-end

these would make an item span the rows/columns 5 and 6

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

grid-area: 2 / 3 / 4 / span 5;

A

Shorthand for

grid-row-start: 2
grid-column-start: 3
grid-row-end: 4
grid-column-end: span 5

the item will occupy rows two and three and columns three through eight.

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

grid-template-areas

A

The CSS grid-template-areas property allows the naming of sections of a webpage to use as values in the grid-row-start, grid-row-end, grid-column-start, grid-column-end, and grid-area properties. They specify named grid areas within a CSS grid.

...
grid-template-areas: "head head"
                       "nav nav" 
                       "info services"
                       "footer footer";
  grid-template-rows: 300px 120px 800px 120px;
  grid-template-columns: 1fr 3fr; 
}

header {
grid-area: head;
}

makes the tag content take up the first row and both columns.

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

justify-items

A

A property that positions grid items along the inline, or row, axis. This means that it positions items from left to right across the web page. This positions them within the COLUMN

Values:

start — aligns grid items to the left side of the grid area

end — aligns grid items to the right side of the grid area

center — aligns grid items to the center of the grid area

stretch — stretches all items to fill the grid area

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

justify-content

A

Positions the ENTIRE grid/columns along the row axis.

Values:

start — aligns the grid to the left side of the grid container

end — aligns the grid to the right side of the grid container

center — centers the grid horizontally in the grid container

stretch — stretches the grid items to increase the size of the grid to expand horizontally across the container

space-around — includes an equal amount of space on each side of a grid element, resulting in double the amount of space between elements as there is before the first and after the last element

space-between — includes an equal amount of space between grid items and no space at either end

space-evenly — places an even amount of space between grid items and at either end

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

align-items

A

A property that positions grid items along the block, or column axis. This means that it positions items from top to bottom. This positions them within the ROW

Values:

start — aligns grid items to the top side of the grid area

end — aligns grid items to the bottom side of the grid area

center — aligns grid items to the center of the grid area

stretch — stretches all items to fill the grid area

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

align-content

A

Positions the ENTIRE grid/rows along the column axis, or from top to bottom.

Values:

start — aligns the grid to the top of the grid container

end — aligns the grid to the bottom of the grid container

center — centers the grid vertically in the grid container

stretch — stretches the grid items to increase the size of the grid to expand vertically across the container

space-around — includes an equal amount of space on each side of a grid element, resulting in double the amount of space between elements as there is before the first and after the last element

space-between — includes an equal amount of space between grid items and no space at either end

space-evenly — places an even amount of space between grid items and at either end

17
Q

justify-self

A

Specifies how an individual element should position itself with respect to the row axis.

This property will override justify-items for any item on which it is declared.

18
Q

align-self

A

Specifies how an individual element should position itself with respect to the column axis.

This property will override align-items for any item on which it is declared.

19
Q

grid-auto-rows

grid-auto-columns

A

grid-auto-rows specifies the height of implicitly added grid rows.

grid-auto-columns specifies the width of implicitly added grid columns.

20
Q

grid-auto-flow

A

Specifies whether new elements should be added to rows or columns.

Values:

row — specifies the new elements should fill rows from left to right and create new rows when there are too many elements (default)

column — specifies the new elements should fill columns from top to bottom and create new columns when there are too many elements

dense — this keyword invokes an algorithm that attempts to fill holes earlier in the grid layout if smaller elements are added

You can pair row and column with dense, like this: grid-auto-flow: row dense;.