Slide 1

Slide 1 text

Introduction to CSS Grid Layout

Slide 2

Slide 2 text

Bastian Heist • Full-Stack Developer @ Sandstorm since 2015 • Neos CMS supporter since 2015 • Freelance Web Developer since 2009 • SAP ERP Consultant @ Merck, 2008-2015 @beheist

Slide 3

Slide 3 text

WHY another one? Flexbox Float Column Tables

Slide 4

Slide 4 text

two-dimensional grid-based layout system, optimized for user interface design CSS Grid Layout Module Level 1 W3C Candidate Recommendation, 29 September 2016

Slide 5

Slide 5 text

Content 1. Concepts & Terminology 2. Defining a Grid 3. Arranging Items on the Grid

Slide 6

Slide 6 text

Concepts & Terminology

Slide 7

Slide 7 text

Grid Container .container { display: grid; }

Slide 8

Slide 8 text

Grid Cell An abstract cell 
 defined in CSS.

Slide 9

Slide 9 text

Grid Item .container { display: grid; }
? ? ?

Slide 10

Slide 10 text

Grid Item != Grid Cell Items can be aligned 
 on the grid areas.

Slide 11

Slide 11 text

Grid Line

Slide 12

Slide 12 text

Grid Track An area between 2 grid lines. Rows or columns.

Slide 13

Slide 13 text

Grid Area An area confined by 4 grid lines.

Slide 14

Slide 14 text

Defining a Grid

Slide 15

Slide 15 text

#container { display: grid; // 3 columns grid-template-columns: 1rem 1rem 1rem; // 2 rows grid-template-rows: 1rem 1rem;
 } Defining a 3x2 Grid

Slide 16

Slide 16 text

#container { display: grid; grid-template-columns: [v0] 1rem [v1] 1rem [v2] 1rem [v3]; grid-template-rows: [h0] 1rem [h1] 1rem [h2]; } Lines Can Be Named [h0] [h1] [h2] [v0] [v1] [v2] [v3]

Slide 17

Slide 17 text

#container { display: grid; grid-template-columns: [v0] 1rem [v1] 1rem [v2] 1rem [v3]; grid-template-rows: [h0] 1rem [h1] 1rem [h2]; grid-template-areas: "top top top" "left . right"; } Areas Can Be Named, Too top left right

Slide 18

Slide 18 text

#container { display: grid; grid: [r0-start] "top top top" 1rem [r0-end] [r1-start] "left . right" 1rem [r1-end]; } Typing Sucks… top left right [r0-start] [r0-end] [r1-start] [r1-end]

Slide 19

Slide 19 text

Arranging Items on a Grid

Slide 20

Slide 20 text

#container {…} #container header { grid-column-start: 1; grid-column-end: 4; grid-row-start: 1; grid-row-end: 2; } Arranging Items Between Lines index starts at 1

Slide 21

Slide 21 text

[…] #container section { grid-column-start: v0; grid-column-end: v1; grid-row-start: h1; grid-row-end: h2; } Remember the Named Lines? [h0] [h1] [h2] [v0] [v1] [v2] [v3]

Slide 22

Slide 22 text

[…] #container aside { grid-column: v2 / v3; grid-row: h1 / h2; } —— OR —— #container aside { grid-area: h1 / v2 / h3 / v3; } Shorthands! [h0] [h1] [h2] [v0] [v1] [v2] [v3]

Slide 23

Slide 23 text

[…] #container header { grid-area: top; } #container section { grid-area: left; } #container aside { grid-area: right; } Align Items on Areas top left right

Slide 24

Slide 24 text

Demo Time!

Slide 25

Slide 25 text

But Wait, There’s More! • Grid Gaps • Justify & Align Grid Items and Content • Auto-generated Columns & Rows • Subgrids • Auto Layout / Auto Flow (!)

Slide 26

Slide 26 text

Awesome! Can I use it now?

Slide 27

Slide 27 text

http://caniuse.com/#search=grid

Slide 28

Slide 28 text

To try it now: chrome://flags/

Slide 29

Slide 29 text

One More Thing!

Slide 30

Slide 30 text

13.3. - 19.3. make-rhein-main.de/webweek 14.3. 19:00 Neos Meetup Rhein/Main

Slide 31

Slide 31 text

Okay, One More Thing!

Slide 32

Slide 32 text

grid transforms ♥

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Thank you! @beheist

Slide 35

Slide 35 text

• W3C CSS Grid Layout Candidate Recommendation: https://www.w3.org/TR/css-grid-1/ • Grid Examples: http://gridbyexample.com/ • The Complete Guide To Grid: https://css-tricks.com/snippets/css/complete-guide-grid/ Sources & Resources