Grid - Concepts Flashcards
What is the CSS Grid layout?
The CSS grid lets you define a two-dimensional layout of columns and rows and then place elements within the grid. Some elements may only fill one cell of the grid; others can span multiple columns or rows; could position themselves so they actually overlap and layer, similar to CSS positioned elements.
Source: Keith J. Grant (2018). CSS in Depth. Manning Publications.
What is a grid?
A grid is a set of intersecting horizontal and vertical lines defining columns and rows. Elements can be placed onto the grid within these column and row lines.
Source MDN
What are the properties of a grid?
-
Fixed and flexible track sizes - using
px
, percentages or the newfr
units. - Item placement - Items can be placed explicitly using line numbers, names or by targeting an area of the grid implicitly.
- Creation of additional tracks to hold content - can add additional rows and columns when needed.
- Alignment control - can control how the items align once placed into a grid area, and how the entire grid is aligned.
- Control of overlapping content - More than one item can be placed into a grid cell or area and they can partially overlap each other.
Source MDN
What is a grid container?
The element on which display: grid
or display: inline-grid
is applied. It’s the direct parent of all the grid items. In this example container is the grid container.
<div class="container"> <div class="item item-1"> </div> <div class="item item-2"> </div> <div class="item item-3"> </div> </div>
Source css-tricks
What is a grid item?
The children (i.e. direct descendants) of the grid container. Here the item elements are grid items, but sub-item isn’t.
<div class="container"> <div class="item"></div> <div class="item"> <p class="sub-item"></p> </div> <div class="item"></div> </div>
Source css-tricks
What is a 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. Here the yellow line is an example of a column grid line.
Source css-tricks
What is a 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.
Source css-tricks
What is a 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.
Source css-tricks
What is a grid area?
The total space surrounded by four grid lines. A grid area may be composed of any number of grid cells. Here’s the grid area between row grid lines 1 and 3, and column grid lines 1 and 3.
Source css-tricks
What does the fr
unit do?
The fr
unit allows you to set the size of a track as a fraction of the free space of the grid container. For example, this will set each item to one third the width of the grid container:
.container { grid-template-columns: 1fr 1fr 1fr; }
The free space is calculated after any non-flexible items. In this example the total amount of free space available to the fr
units doesn’t include the 50px
:
.container { grid-template-columns: 1fr 50px 1fr 1fr; }
Source css-tricks
What properties have no effect on a grid-item?
float, display: inline-block, display: table-cell, vertical-align and column-*
properties have no effect on a grid item.
Source css-tricks
What are fr units?
fr units essentially mean “fraction of the remaining space”. So a declaration like:
grid-template-columns: 1fr 3fr;
Means, loosely, 25% 75%. Except that those percentage values are much more firm than fractional units are. For example, if you added padding to those percentage-based columns, now you’ve broken 100% width (assuming a content-box
box model).
Source css-tricks
What is an explicit grid?
An explicit grid is a manually defined grid. In other words the part of the grid were you define a fixed number of lines and tracks that form the grid by using the properties grid-template-rows, grid-template-columns,
and grid-template-areas
.
Example:
.grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 100px 100px; grid-gap: 20px; }
Source css-tricks
What is an implicit grid?
If there are more grid items than cells in the grid or when a grid item is placed outside of the explicit grid, the grid container automatically generates grid tracks by adding grid lines to the grid. The explicit grid together with these additional implicit tracks and lines forms the so called implicit grid.
Source css-tricks
What is a flexible grid?
A grid that doesn’t explicitly declare the number of rows or columns, but automatically creates them based on somewhat loose instructions and the content you provide.
Source css-tricks