Grid Flashcards
In a nutshell, what is the difference between flexbox and grid?
Flex box is for alignment
Grid is for layout
Set a container to grid
set a container to grid inline (even if it’s block)
What’s the difference
display: grid
display: inline-grid
Inline grid is inline. It also doesn’t make the grid container auto fill the horizontal space. It is the size of the items.
define 2 columns and 2 rows to place 4 grid items
define 3 columns and 2 rows to place 4 grid items
What will happen with the missing item?
.container { display: grid; grid-template-columns: 50px 50px; grid-template-rows: 50px 50px; }
.container { display: grid; grid-template-columns: 50px 50px 50px; grid-template-rows: 50px 50px; }
The last grid item just isn’t fill in
Shorthand for grids and rows
forward slash .container { display: grid; grid-template: 50px 50px / 50px 50px 50px; }
With: .container { display: grid; grid-template-columns: 50px 50px; grid-template-rows: 50px 50px; } what happens with the 5th item?
Looks like:
Item 1 Item 2
Item 3 Item 4
Item 5
It’s still added to the grid, but those grid items have undefined height. The width doesn’t disturb the set width
IF the height is set. It follows overflow rules.
Control whether the overflow goes down or to the right
Down
grid-auto-flow: row;
Right
grid-auto-flow: column;
Add a gap between columns
Add a gap between rows
Shorthand for both
row-gap: 40px
column-gap: 10px
gap: row col
gap: 40px 10px
What is an implicit vs explicit grid
explicit is when you have enough items defined.
Implicit when it automatically creates rows or columns for extra items for undefined space.
How to distinguish implicitly and explicitly created rows in dev tools?
explicit dashed and more solid
implicit dotted
How to view grid in browser
under layout> grid overlays> select the grid containers.
How are grid items auomatically named/numbered?
They are not. The lines are numbered.
Far left line is 1 and they increase from there.
AND
Far right line is -1 and decreases to the left
Create a custom name for a grid line
.container {
grid-template-columns: [first] 40px [line2] 50px [line3] auto [col4-start] 50px [five] 40px [end];
grid-template-rows: [row1-start] 25% [row1-end] 100px [third-line] auto [last-line];
}
Create multiple custom names for the same grid line
.container {
grid-template-rows: [row1-start] 25% [row1-end row2-start] 25% [row2-end];
}
Repeat grid template setup
.container {
grid-template-columns: repeat(3, 20px [col-start]);
}
Which is equivalent to this:
.container {
grid-template-columns: 20px [col-start] 20px [col-start] 20px [col-start];
}
Grid terms: grid container grid item grid line grid cell grid track grid area
grid container- The element on which display: grid is applied. It’s the direct parent of all the grid items. In this example container is the grid container.
grid item- The children (i.e. direct descendants) of the grid container. Here the item elements are grid items, but sub-item isn’t.
grid line- The dividing lines that make up the structure of the grid. They can be either vertical (“column grid lines”) or horizontal (“row grid lines”) and reside on either side of a row or column.
grid cell -The space between two adjacent row and two adjacent column grid lines. It’s a single “unit” of the grid. Here’s the grid cell between row grid lines 1 and 2, and column grid lines 2 and 3.
grid track- The space between two adjacent grid lines. You can think of them as the columns or rows of the grid. Here’s the grid track between the second and third-row grid lines.
grid area- Multiple cells. The total space surrounded by four grid lines. A grid area may be composed of any number of grid cells.