box-sizing: border-box as it includes padding and bordersdisplay: grid;
grid-template-columns: (size) (size)... defines explicit columns
auto to auto size columns to use up rest of the screen widthgrid-gap: (size) separates columns and rowsgrid-template-columns: (size) (size)... or grid-template-rows: (size) (size)...grid-auto-columns: (size) (size)... and grid-auto-rows: (size) (size)...
grid-auto-flow: column or grid-auto-flow: columngrid-template-columns: 100px 1fr 1fr 2fr (1fr = fraction) makes 1 100px column, the other share the rest of the screen size with the defined ratio 1:1:2.auto and 1frgrid-template-columns: repeat(4, 1fr 2fr); instead of grid-template-columns: 1fr 2fr 1fr 2fr;grid-column: span 3 or grid-row: span 3grid-column-start: 2 and grid-column-end: 5 or shorthand grid-column: 2 / 5 or grid-column: 2 / span 3grid-column: 2 / 5 = grid-column: 2 / -2 for a 5 column layout.grid-template-column or grid-template-row you can use auto-fit or auto-fill as first argument.auto-fill will create as many columns/rows as possible, making it possible to move items at the end of the screenauto-fit will create as many columns/rows as possible but without making the grid physically wider
grid-column-end for an item.grid-template-column or grid-template-row you can use the minmax function as second argument.fr for the max width and auto-fit in the repeat function, this can help to create responsive designs.grid-template-column: fit-content(100px) 150px 150px which for the first column will fit the content into the box, but set an upper limit to 100px for the width.Layout the grid as follows
.content {
gird-template-columns: (add your values)
grid-template-area:
"sidebar-1 header sidebar-2"
"sidebar-1 content sidebar-2"
"footer footer footer";
}
.item1 {
grid-area: sidebar-1;
}
.item2 {
grid-area: header;
}
.item3 {
grid-area: sidebar-2;
}
.item4 {
grid-area: content;
}
.item5 {
grid-area: footer;
}
Now you can use media queries and redefine the grid area:
@media (max-width: 500px) {
.container {
grid-template-areas:
"content content content"
"sidebar-1 sidebar-1 sidebar-2"
"footer footer footer";
}
}
When you have areas, you get line names for free, so footer-start and footer-end is automatically available for things like grid-column: footer-start / footer-end;
grid-template-columns: [first-line] 1fr [second-line] 1fr [last-line];grid-column: first-line / last-line instead of grid-column: 1 / 3grid-auto-flow: dense; this space is filled with subsequent items.