Флексбокс имеет одновременно только одно измерение в разметке (или строки, или колонки).
CSS-гриды имеют одновременно два измерения (и строки, и колонки).
<div class="grid-wrapper">
<div> ... </div>
...
<div> ... </div>
</div>
.grid-wrapper {
display: grid;
grid-template-columns: 20% 80%;
// shortcut
grid-template: grid-template-columns / grid-template-rows;
}
.grid-wrapper {
display: grid;
grid-template-columns: 20% 30% 50%;
}
.grid-wrapper {
display: grid;
grid-template-columns: 20% 30% 50%;
}
.grid-wrapper {
display: grid;
grid-template-columns: 20% 20% 60%;;
grid-template-rows: 50px 100px;
}
.grid-wrapper {
display: grid;
grid-template-columns: 20% 20% 60%;;
grid-template-rows: 50px 100px;
// fix
grid-auto-rows: 30px;
// adaptive (можно и колонкам)
grid-auto-rows: minmax(50px, auto);
}
.grid-wrapper {
display: grid;
grid-template-columns: 20% 30% 50%;
grid-column-gap: 15px;
}
.grid-wrapper {
display: grid;
grid-template-columns: 30% 30% 40%;
grid-row-gap: 15px;
}
.grid-wrapper {
display: grid;
grid-template-columns: 30% 30% 30%;
grid-gap: 15px 5px;
}
.grid-wrapper {
display: grid;
grid-gap: 5px;
grid-template-columns: 2fr 1fr 2fr 1fr;
// or with repeat
grid-template-columns: repeat(2, 2fr 1fr);
}
.grid-wrapper {
display: grid;
grid-template-columns: minmax(10px, 50px) 1fr 1fr;
grid-template-rows: 25px 25px 25px;
grid-auto-rows: minmax(50px, auto);
grid-gap: 5px;
grid-auto-flow: column;
}
.grid-wrapper {
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
}
.grid-wrapper {
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(3, 1fr);
}
.grid-wrapper > div:nth-child(1) {
// -1 - full-column
grid-column-start: 1
grid-column-end: 3
grid-column: 1 / 3;
grid-row-start: 1
grid-row-end: 3
grid-row: 1 / 3;
// shortcut
grid-area: 1 / 1 / 3 / 3;
}
<div class="grid">
<header></header>
<aside></aside>
<main></main>
<footer></footer>
</div>
.grid {
display: grid;
grid-gap: 5px;
grid-template-columns: 2fr, 4fr;
grid-template-areas:
"header ."
"aside main"
"footer main"
;
}
header {
grid-area: header;
}
aside {
grid-area: aside;
}
main {
grid-area: main;
}
footer {
grid-area: footer;
}
.grid-wrapper {
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(3, 1fr);
// выравнивание по горизонтали
justify-items: stretch* | start | center | end;
// выравнивание по вертикали
align-items: stretch* | start | center | end;
}
.grid-wrapper > div:nth-child(1){
align-self: stretch* | start | center | end;
justify-self: stretch* | start | center | end;
}