by Tab Atkins Jr. (Google)
at CSS WG Blog
.grid { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: 100px 1fr auto; } .title { grid-column: 1; grid-row: 1; } .menu { grid-column: 1; grid-row: 2 / span 2; } .main { grid-column: 2; grid-row: 1 / span 2; } .footer { grid-column: 2; grid-row: 3; }
display: grid
: Defines a grid container.grid-template-columns
and grid-template-rows
: Specify the track breadths.grid-column
and grid-row
: Determine a grid item's size and location within the grid.<div class="grid"> <div class="title">Title</div> <div class="menu">Menu</div> <div class="main">Main</div> <div class="footer">Footer</div> </div>
fr
- free space - unit)max-content
min-content
minmax(min, max)
auto
.grid { display: grid; grid-template-areas: "title title title social" "menu main main social" "menu main main social" "footer footer footer footer"; } .title { grid-area: title; align-self: center; justify-self: center; } .menu { grid-area: menu; align-self: start; } .main { grid-area: main; } .social { grid-area: social; align-self: end; justify-self: right; } .footer { grid-area: footer; align-self: start; }
grid-template-areas
specifies named grid areas that can be referenced to position grid items.form { display: grid; grid-auto-flow: row; } label { grid-column: 1; } input, textarea { grid-column: 2; } .controls { grid-column: 1 / span 2; }
grid-auto-flow
controls the direction in which the grid items are automatically placed.