HTML5DevConf Autumn 2015 / 19-20 October 2015 (San Francisco)
CSS Grid Layout implementor (Chromium/Blink & Safari/WebKit)
Member of Igalia Web Platform Team
<table>
float
display: inline-block;
display: table;
display: flex;
display: grid;
display: grid;
New formatting context
grid-template-columns
& grid-template-rows
Create boxes from CSS!
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
<div class="d">D</div>
</div>
grid-column
& grid-row
DOM order ≠ Visual order
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
Use custom identifiers to reference lines
A line can have several names
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
grid-template-areas
### ###### ###### #### #### ### ######## ######## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ## ## ## ## ## ######## ## ######### ## ## ## ## ######### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ###### #### #### ## ## ## ## ##
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
<div class="d">D</div>
</div>
CSS Box Alignment spec
Horizontal & vertical centering!
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
grid-row-gap
& grid-column-gap
<div class="grid">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
<div class="d">D</div>
<div class="e">E</div>
</div>
grid-auto-flow
<form>
<label>Input</label>
<input>
<label>Checkbox</label>
<input type="checkbox">
<button>Submit form</button>
</form>
Flexible track sizing
.grid {
display: grid;
grid: 200px 1fr / 100px 1fr auto;
grid-template-areas: "header header"
"aside main "
"aside footer";
}
@media (max-width: 400px) {
.grid {
grid: 1fr / 100px 1fr 100px auto;
grid-template-areas: "header"
"main "
"aside "
"footer"; }
}
auto-fill
& auto-fit
keywords for repeat()
<div class="grid">
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
<div>E</div>
</div>
<form><ul>
<li><label>Input</label><input></li>
<li><label>Checkbox</label><input type="checkbox"></li>
<li><button>Submit form</button></li>
</ul></form>
<div class="grid">
<div class="title">Title</div>
<div class="nav">Nav</div>
<div class="main">Lorem ipsum...</div>
<div class="aside">Ad</div>
<div class="aside">Adword</div>
</div>
.grid { display: grid;
width: 800px;
grid-template-columns: 200px 1fr auto;
grid-template-rows: 100px auto; }
.title { grid-row: 1; grid-column: 2; }
.nav { grid-row: 2; grid-column: 1; }
.main { grid-row: 2; grid-column: 2; }
.aside { grid-column: 3; }
200px
is faster than auto
60% faster (20x10 grid)
100% faster (100x20 grid)
140% faster (100x100 grid)
auto
is faster than 1fr
40% faster
Vertical stretch
in auto-sized items is slower than other (e.g. start
)
20% slower
Avoid horizontal stretch
(e.g. start
) in auto-sized items is slower
10% slower
CSS Grid Layout - https://drafts.csswg.org/css-grid/
Started by Microsoft in 2010
Last Working Draft 17 September 2015
W3C Test Suite