CSS Grid Flashcards
grid-template-areas
Allows you to name sections of your web page to use as values in the grid-row-start, grid-row-end, grid-column-start,grid-column-end, and grid-area properties.
Where is grid-template-areas declared?
This property is declared on grid containers.
What property do you use to overlap elements?
When overlapping elements, it is generally easiest to use the grid-area property with grid row names. Remember that grid-area will set the starting and ending positions for both the rows and columns of an item.
What are the 2 axes in a grid layout?
The column (or block) axis and the row (or inline) axis.
What does the column axis do in CSS grid?
The column axis stretches from top to bottom across the web page.
What does the row axis do in CSS grid?
The row axis stretches from left to right across the web page.
justify-items
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.
Where is justify-items declared?
This property is declared on grid containers.
What are the available values for justify-items?
start
end
center
stretch
justify-items: start;
Aligns grid items to the left side of the grid area
justify-items: end;
Aligns grid items to the right side of the grid area
justify-items: center;
Aligns grid items to the center of the grid area
justify-items: stretch;
Stretches all items to fill the grid area
justify-content
We can use justify-content to position the entire grid along the row axis.
Where is justify-content declared?
This property is declared on grid containers.
What are the available values for justify-content?
start
end
center
stretch
space-around
space-between
space-evenly
NOTE: There are several other values that justify-content accepts, which you can read about on the Mozilla Developer Network.
justify-content: start;
Aligns the grid to the left side of the grid container
justify-content: end;
Aligns the grid to the right side of the grid container
justify-content: center;
Centers the grid horizontally in the grid container
justify-content: stretch;
Stretches the grid items to increase the size of the grid to expand horizontally across the container
justify-content: 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
justify-content: space-between;
Includes an equal amount of space between grid items and no space at either end
justify-content: space-evenly;
Places an even amount of space between grid items and at either end
align-items
A property that positions grid items along the block, or column axis. This means that it positions items from top to bottom.
Where is align-items declared?
This property is declared on grid containers.
What are the available values for align-items?
start
end
center
stretch
NOTE: There are several other values that align-items accepts, which you can read about on the Mozilla Developer Network.
align-items: start;
Aligns grid items to the top side of the grid area
align-items: end;
Aligns grid items to the bottom side of the grid area
align-items: center;
Aligns grid items to the center of the grid area
align-items: stretch;
Stretches all items to fill the grid area
align-content
Positions the rows along the column axis, or from top to bottom
Where is align-content declared?
Declared on grid containers
What are the available values for align-content?
start
end
center
stretch
space-around
space-between
space-evenly
NOTE: There are several other values that align-content accepts, which you can read about on the Mozilla Developer Network.
align-content: start;
Aligns the grid to the top of the grid container
align-content: end;
Aligns the grid to the bottom of the grid container
align-content: center;
Centers the grid vertically in the grid container
align-content: stretch;
Stretches the grid items to increase the size of the grid to expand vertically across the container
align-content: 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
align-content: space-between;
Includes an equal amount of space between grid items and no space at either end
align-content: space-evenly;
Places an even amount of space between grid items and at either end
The ___________ and ___________ properties specify how all grid items contained within a single container will position themselves along the row and column axes, respectively.
justify-items and align-items
justify-self
Specifies how an individual element should position itself with respect to the row axis
What property will override justify-items for any item on which it is declared?
justify-self
align-self
Specifies how an individual element should position itself with respect to the column axis
What property will override align-items for any item on which it is declared?
align-self
Where is justify-self declared?
This property is declared on grid items
Where is align-self declared?
This property is declared on grid items
__________ and __________ accept the same values as align-items and justify-items.
align-self and justify-self
Name an instance in which we don’t know how much information we’re going to display
For example, consider online shopping. Often, these web pages include the option at the bottom of the search results to display a certain quantity of results or to display ALL results on a single page. When displaying all results, the web developer can’t know in advance how many elements will be in the search results each time.
Implicit grid
The implicit grid is an algorithm built into the specification for CSS Grid that determines default behavior for the placement of elements when there are more than fit into the grid specified by the CSS.
What is the default behavior of the implicit grid?
The default behavior of the implicit grid is as follows: items fill up rows first, adding new rows as necessary. New grid rows will only be tall enough to contain the content within them.
What two properties to specify the size of grid tracks added implicitly within CSS Grid?
grid-auto-rows and grid-auto-columns
Where is grid-auto-rows and grid-auto-columns declared?
These properties are declared on grid containers.
grid-auto-rows
Specifies the height of implicitly added grid rows.
grid-auto-columns
Specifies the width of implicitly added grid columns.
________ and ________ accept the same values as their explicit counterparts, grid-template-rows and grid-template-columns:
pixels (px)
percentages (%)
fractions (fr)
the repeat() function
grid-auto-rows and grid-auto-columns
How can you specify the order in which implicitly-added rows and columns are rendered?
grid-auto-flow
grid-auto-flow
Specifies whether new elements should be added to rows or columns, and is declared on grid containers.
What are the available values for grid-auto-flow?
row
column
dense
You can pair row or column with dense, like this: grid-auto-flow: row dense;
grid-auto-flow: row;
Specifies the new elements should fill rows from left to right and create new rows when there are too many elements (default)
grid-auto-flow: column;
Specifies the new elements should fill columns from top to bottom and create new columns when there are too many elements
grid-auto-flow: dense;
This keyword invokes an algorithm that attempts to fill holes earlier in the grid layout if smaller elements are added
Which three values do the justify-content and align-items properties share?
start, end, center
Imagine we have a grid with the following CSS properties, with 4 boxes inside of it. If we added a fifth box to the HTML, what height would it have?
.grid {
grid-template-rows: repeat(2, 50px);
grid-template-columns: repeat(2, 100px);
grid-auto-rows: 60px;
grid-auto-columns: 70px;
}
60px
Any implicitly created rows will have the height specified by grid-auto-rows, not the height of the explicitly created rows.
Imagine we have a grid with 2 explicitly defined rows and 2 explicitly defined columns and no other grid properties set in the CSS, with the following divs inside of it. If we added a <div class="box">E</div> to the HTML after box D, where would box E appear on the page
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
It would appear underneath box C in a new row
Which of the following display values will set an element to be a grid container and inline?
inline-grid
Imagine we have a grid with 4 items in it, with the following CSS properties. What width would the 3rd column be?
.grid {
grid-auto-columns: 100px 200px;
grid-auto-flow: column;
}
100px
The boxes will fill up implicitly created columns which alternate between being 100px and 200px. Odd rows will be 100px in size.