grid-area css code example
Example 1: css grid-area names
.grid {
display: grid;
grid-gap: 20px;
grid-template-rows: [header-start] 20vh [header-end] ;
grid-template-columns: [sidebar-start] 1fr 2fr [sidebar-end] 1fr 2fr 1fr 2fr;
}
.header {
grid-row: header-start;
grid-column: 1 / -1;
}
.sidebar {
grid-row: 2;
grid-column: sidebar-start / sidebar-end;
}
Example 2: grid-area top top
.item-a {
grid-area: header;
}
.item-b {
grid-area: main;
}
.item-c {
grid-area: sidebar;
}
.item-d {
grid-area: footer;
}
.container {
display: grid;
grid-template-columns: 50px 50px 50px 50px;
grid-template-rows: auto;
grid-template-areas:
"header header header header"
"main main . sidebar"
"footer footer footer footer";
}
Example 3: unknown property grid-template-areas
.sidebar{
grid-area:sidebar;
background:aqua;
}
.grid_container{
display:grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: 1fr 3fr;
grid-template-areas:
"sidebar ."
"sidebar .";
background:pink;
height:300px;
}
Example 4: grid-area
.item {
grid-area: | / / / ;
}