12 CSS Grid Flashcards
Turn element into gridcontainer, where children are arranged on a grid
display: grid;
Create grid columns of specific sizes
Create grid rows of specific sizes
What happens if there are more items than the grid can allow
grid-template-columns: 50px 70px;
creates 1 column 50px wide, 1 column 70px wide
grid-template-rows: 50px 70px;
They are created onto new rows with a default height
Units of measurement to control the size of rows and columns
px, em and the other regulars
fr- size is a fraction of the available space
grid-template-row: 1fr 4fr;
frame is set into 5 pieces,
auto- sets the column or row to the width or height of its content,
%: adjusts the column or row to the percent width of its container.
add a gap in between rows or columns
grid-column-gap: 10px;
grid-row-gap: 10px;
grid gap short version
grid-gap: 10px 20px;
Make a box take up more cells
grid-column: 1/3
from the first gap to the third gap.
n/n+1 would just be normal space. n/n+2 would be 2 spaces.
grid-row:2/4
Control left-right spacing of all cells
11
justify-items: center; /* Pack items around the center /
justify-items: start; / Pack items from the start /
justify-items: end; / Pack items from the end /
justify-items: flex-start; / Equivalent to ‘start’. Note that justify-items is ignored in Flexbox layouts. /
justify-items: flex-end; / Equivalent to ‘end’. Note that justify-items is ignored in Flexbox layouts. /
justify-items: self-start;
justify-items: self-end;
justify-items: left; / Pack items from the left /
justify-items: right; / Pack items from the right */
Control top-bottom spacing of all cells
5
align-items: center; /* Pack items around the center /
align-items: start; / Pack items from the start /
align-items: end; / Pack items from the end /
align-items: flex-start; / Pack flex items from the start /
align-items: flex-end; / Pack flex items from the end */
Control left-right spacing of content within a cell
justify-self:
align-self:
Set the area of a grid cell
Merge certain cells together
How do you denote an empty cell?
How do you assign an item to the area?
grid-template-areas:
“a a a”
“. c c “
“footer footer footer”;
each word is 1 cell
each “ “ is 1 row
This merges a into 1 cell
c into 1 cell
footer into 1 cell
. denotes an empty cell
Assign with
.item1 {
grid-area: header;
}
Set the area of a grid cell on the fly without using a template
item1 {
grid-area: 1/1/2/4;
}
(rows 1 to 2 and columns 1 to 4)
grid-area: horizontal line to start at / vertical line to start at / horizontal line to end at / vertical line to end at;
Make lots of rows or columns
grid-template-rows: repeat(100, 50px);
100 rows 50 px wide
grid-template-columns: repeat(100, 50px)
Repeat a non uniform pattern
grid-template-columns: repeat(2, 1fr 50px) 20px;
2 sets if 1fr 50, then 20 px
equiv to
grid-template-columns: 1fr 50px 1fr 50px 20px;
Set min and max size of column or row
grid-template-columns: 100px minmax(50px, 200px);
create two columns; the first is 100px wide, and the second has the minimum width of 50px and the maximum width of 200px.
grid-template-rows: 100px minmax(50px, 200px);
Combine repeat and minmax
grid-template-columns: repeat(3, minmax(90px, 1fr));