Jull Weber
jull@monkeykodeagency.comThe element containing a grid,
defined by setting display:grid
You can nest grid containers inside grid containers and have as many as you like.
Direct descendant of container.
Only first level descendants are placed on the grid, children, not at all.
The intersection between a grid row and grid column, like table-cell. These will auto-populate from Top Left to Bottom Right.
The full row or column. Horizontal or Vertical.
One or more cells.
Same as gutter. Can be horizontal, vertical, or both. You are creating empty space in the grid track, so whatever color behind the grid will come through.
grid-template-columns: 2fr 1fr 1fr;
grid-template-columns: 63px 20vw 10% 40em 42vh;
grid-template-rows: auto 1fr 3fr
grid-template-rows:1fr 1fr 2fr
grid-template-columns: 20em 1fr 1fr 2fr 3fr;
So if you have "1fr 2fr," it'll divide the area into 3 sections giving the latter 66 2/3 % and the first one 33 1/3%.
Lets you define the minimum or maximum width of a column or row.
Great for responsive design.
grid-template-rows: 1fr minmax(10em, 20em)
If you have a list of similar columns you can use repeat() as a shorthand notation.
grid-template-rows: repeat(2, 1fr) 2fr
You can do alternating widths by adding a additional units
grid-template-rows: repeat(2, 1fr 30px) 2fr
Chrome comes with basic Grid Overlay in Inspector.
Firefox gives you the grid overlay and a number of other helpful tools. You'll notice a new tab "Layout" gets added when working with grids.
grid-column:2/4; grid-row: 2/3;
grid-column: 2/2 span
You tell it where on the grid to start and the second argument how far to span.
.site {
display:grid;
grid-template-columns: [begin-edge] 2fr [halfway] 1fr [quarter] 1fr [end-edge];
grid-template-rows: auto 1fr 3fr;
}
.masthead {
grid-column: halfway/end-edge
}
Since it can get clunky naming all your sections there is a shorthand that you can use.
.masthead {
grid-column: main-end/sidebar;
grid-row: 2/3;
}
.page-title {
grid-column: main/sidebar;
grid-row: 1/2;
}
.main-content {
grid-column: main;
grid-row: 2/4;
}
grid-template-areas:
"title title title"
"main header ."
"main sidebar footer";
grid-gap:1em
grid-column-gap:1em
grid-row-gap:1em
grid-gap: 1em 2em
@supports (grid-area:auto) {
...
}
grid-template-columns: 15em minmax(auto, 30em) 15em;
justify-content: center;
You can easily do things you couldn't even dream of doing before!
.sidebar {
display: inherit;
grid-template-columns: inherit;
grid-column: 1/4;
grid-row: 2/3;
height: 0;
}
.twin:last-of-type {
grid-column: 3/4;
}
/* Disable fallback max-width center aligned rule: */
.site {
max-width: none;
}
/* Four-column layout: Two center columns have total width of 50em: */
.main-area > *,
.colophon {
display: grid;
grid-template-columns: 1fr repeat(2, minmax(auto, 25em)) 1fr;
}
/* Center items by placing them in the two center columns: */
.splash-content,
.more-content,
.buckets ul {
grid-column: 2/4;
}
/* Use automatic grid placement + span to let each item span two columns: */
.twin,
.colophon aside {
grid-column: 2 span;
}
Combine flexbox and grid to achieve full heights in the cells.
.card a {
display: grid;
grid-template-columns: 6em auto;
grid-template-rows: 1fr 1fr;
padding: 0 1em 0 0;
text-align: left;
}
.time {
grid-column: 1;
grid-row: 1/3;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.card h2 {
grid-column: 2;
grid-row: 1;
align-self: flex-end;
}
.meta {
grid-column: 2;
grid-row: 2;
}
Sooo easy!!! No extra weird dom elements.
grid-column: 1;
grid-row: 1;
*Tip- make text align to the bottom. Use flex!
display:flex; display: flex-end;
.double {
grid-column: span 2;
grid-row: span 2;
}