Grid
Grid track sizes can be specified in many ways, include: absolute units, relative units, percentages, and newer Grid-specific values. Examples: fr unit, minmax() function, auto, and content-based values min-content/max-content. repeat() function, optional auto-fill and auto-fit values.
- display: grid
- display: inline-grid
- grid container
- grid item (direct children of grid container)
- grid line
- grid cell
- grid area
- grid track
Grid Example
grid-template-rows: 50px 200px 50px;
grid-template-columns: 100px 250px 100px;ABCDEFGHIGrid Items Less Than Grid Cells
ABCDEFGGrid Items More Than Grid Cells
ABCDEFGHIJAbsolute Values
ABCDEFGHIAbsolute and Relative Values
grid-template-rows: 1fr 200px 1fr;
grid-template-columns: 100px 1fr 100px;ABCDEFGHIRelative Values
grid-template-rows: 1fr 2fr 1fr;
grid-template-columns: 1fr 2fr 1fr;ABCDEFGHIminmax()
grid-template-rows: 50px 200px 50px;
grid-template-columns: 100px minmax(15em, 25em) 100pxABCDEFGHImin-content, max-content
grid-template-rows: min-content 200px 50px;
grid-template-columns: max-content min-content 100px;The min-content, max-content, and auto values size tracks based on the size of the content within it. The min-content value is the smallest that a track can get without overflowing. The max-content property allots the maximum amount of space needed for the content, even if that means extending the track beyond the boundaries of the grid container. When used as a column width, the column track will be as wide as the widest possible content in t hat track without line wrapping. Auto lets the browser make their 'best judgment' on how to best fit the content while still considering other restrictions in place. minmax() behaves like minmax(min-content, max-content).
The rules continue, but it's rather fussy and complex, so I'll leave the details be for now. p457.
AThe min-content value is the smallest that a track can get without over-flowing.The max-content property allots the maximum amount of space needed for the content, even if that means extending the track beyond the boundaries of the grid container.
When used as a column width, the column track will be as wide as the widest possible content in t hat track without line wrapping.
DThe min-content value is the smallest that a track can get without over-flowing.ABCDrepeat()
grid-template-rows: repeat(2, 50px 8em);
grid-template-columns: repeat(2, 50px 1fr);ABCDEFGHIJABCDEFGHIJrepeat(auto-fill, length), repeat(auto-fit, length)
grid-template-rows: repeat(auto-fill, 100px 50px); grid-template-columns: repeat(auto-fill, 100px 50px);
ABCDEFGHIJABCDEFGHIJgrid-template-areas
grid-template-rows: [header-start] 50px [content-start] 200px [footer-start] 50px;
grid-template-columns: [ads] 100px [main] 1fr [links] 100px;
grid-template-areas:
"header header header"
". main links"
"footer footer footer"grid (shortcut)
Two shortcuts for grid are 'grid' and 'grid-template'. Of the two, using 'grid' is the recommended option unless you want some specific cascading behavior from grid-template. Additionally, neither shortcut should be used for anything except the most simple grids, as more complex grids become much harder to manage with the shortcut style.
grid:
[header-start] "header header header" 50px
[content-start] ". main links" 200px
[footer-start] "footer footer footer" 50px
/[.] 200px [main] 1fr [links] 100px;
Placing Grid Items
Positioning with Lines
One option to placing grid items into the desired location is to specify the line of all four sides of the location.
A shortcut alternative is to specify only one of these properties, then tell the item to 'span' a certain number of cells. The default 'auto' option is for the item to occupy one t rack width.
Positioning Using Lines
grid-row-start: 1;
grid-row-end: 2;
grid-column-start: 1;
grid-column-end: 4;ABCDEFInsertPositioning Using Linees Ex.2
grid-template-rows: 50px 200px 50px;
grid-template-columns: 100px 250px 100px;ABCDEFGHInsertOmitted Columns Starts and Ends
grid-row-start: header-start;
ABCDEFGHInsertOmitted Row Starts/Ends
grid-column-start: 1;
grid-column-end: span 3;ABCDEFInsertLine Position - Span Reverse
grid-column-start: span 3;
grid-column-end: -1;ABCDEFInsertgrid-row: grid-row-start / grid-column-end;
grid-column: grid-column-start / grid-column-end;grid-row: 1 / 2;
grid-column: 1 / span 3;ABCDEFInsertgrid-area: row-start / column-start / row-end / column-end
HeaderAdsMainLinksFootergrid-area: given-name
HeaderAdsMainLinksgrid-auto-rows
grid-auto-columnsRows or columns automatically added to a grid will have the size auto by default, which sizes just large enough to accommodate the heigh or width of the contents. Use these properties to give implicit rows and columns specific dimensions such as to match a rhythm established elsewhere in the grid.
If more than one value is provided to these properties, it acts as a repeating pattern.
-
grid-auto
ABCDEFGHIJ -
grid-auto (with Insert example)
ABCDEFGHIJInsert -
grid-auto-rows: 100px
ABCDEFGHIJ -
grid-auto-flow: columns
ABCDEFGHIJ -
grid-auto-flow: dense rows
TODO: Make this property work properly.
ABCDEFGHIJ -
grid (shortcut, revisited) row auto-flow
TODO: Make this property work properly.
ABCDEFGHIJ -
grid (shortcut, revisited) column auto-flow
TODO: Make this property work properly.
ABCDEFGHIJ -
grid-gap: row column
ABCDEFGHI -
justify-items: start
justify-items: self-start
justify-items: leftABCDEFGHI -
justify-items: end
justify-items: self-end
justify-items: rightABCDEFGHI -
justify-items: center
ABCDEFGHI -
justify-items: stretch
ABCDEFGHI -
justify-items: normal
ABCDEFGHI -
align-items: start
align-items: self-startABCDEFGHI -
align-items: end
align-items: self-endABCDEFGHI -
align-items: center
ABCDEFGHI -
align-items: left
ABCDEFGHI -
align-items: right
ABCDEFGHI -
align-items: stretch
ABCDEFGHI -
align-items: normal
ABCDEFGHI -
justify-content: start
ABCDEFGHI -
justify-content: end
ABCDEFGHI -
justify-content: left
ABCDEFGHI -
justify-content: right
ABCDEFGHI -
justify-content: center
ABCDEFGHI -
justify-content: space-around
ABCDEFGHI -
justify-content:space-between
ABCDEFGHI -
justify-content:space-evenly
ABCDEFGHI -
align-content: start
ABCDEFGHI -
align-content: end
ABCDEFGHI -
align-content: left
ABCDEFGHI -
align-content: right
ABCDEFGHI -
align-content: center
ABCDEFGHI -
align-content: space-around
ABCDEFGHI -
align-content: space-between
ABCDEFGHI -
align-content: space-evenly
ABCDEFGHI