CSS Grid Layout: Specification overview. Implementation status and roadmap

A presentation at BlinkOn 2 in May 2014 in Zürich, Switzerland by Manuel Rego Casasnovas

Slide 1

Slide 1

Slide 2

Slide 2

C S S

G r i d

L a y o u t S p e c i � c a t i o n

o v e r v i e w .

I m p l e m e n t a t i o n

s t a t u s

a n d

r o a d m a p . Manuel Rego Casasnovas - rego@igalia.com

BlinkOn 2 (Zurich)

13-14 May 2014

Slide 3

Slide 3

A b o u t

I g a l i a

&

m e #cssgrid #blinkon #igalia Igalia is an Open Source consultancy founded in 2001. Member of Igalia Browsers Team . Blink and WebKit committer. Working on CSS standards : · · · · CSS Grid Layout CSS Regions

3/28

Slide 4

Slide 4

C S S

G r i d

L a y o u t “ a l l o w s

a u t h o r s

t o

e a s i l y

d e � n e

c o m p l e x ,

r e s p o n s i v e

2

d i m e n s i o n a l l a y o u t s ” by Tab Atkins Jr. (Google)

at CSS WG Blog source: http://www.w3.org/blog/CSS/2014/01/23/css-grid-draft-updated/

Slide 5

Slide 5

C S S

G r i d

L a y o u t

|

I n t r o d u c t i o n #cssgrid #blinkon #igalia Grid based designs were �rst done using tables and more recently �oating divs. Those approaches have issues and a lot of complexity. Lots of CSS frameworks emerging to make things easier. CSS Grid Layout is a powerful and �exible standard de�ned by the W3C . · · · · 5/28

Slide 6

Slide 6

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

I n t r o d u c t i o n #cssgrid #blinkon #igalia CSS Grid Layout provides a mechanism to divide the available space in rows and columns with a set of predictable sizing behaviors . This de�nes a set of grid areas where designers can precisely place the elements of a web page. The Grid Layout spec can be used to intelligently re�ow elements within a web page optimizing locations and sizes depending on the device where the page is rendered in. · · · 6/28

Slide 7

Slide 7

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

C o n c e p t s #cssgrid #blinkon #igalia Grid lines are the horizontal and vertical dividing lines of the grid. · 7/28 Grid track is a generic term for a grid column or grid row. · Grid cell is the space between two adjacent row and two adjacent column grid lines. · Grid area is the logical space used to lay out one or more grid items. It is bound by four grid lines, one on each side of the grid area. ·

Slide 8

Slide 8

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

C o n c e p t s #cssgrid #blinkon #igalia Grid track is a generic term for a grid column . · 8/28 Grid lines are the horizontal and vertical dividing lines of the grid. · or grid row Grid cell is the space between two adjacent row and two adjacent column grid lines. · Grid area is the logical space used to lay out one or more grid items. It is bound by four grid lines, one on each side of the grid area. ·

Slide 9

Slide 9

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

C o n c e p t s #cssgrid #blinkon #igalia Grid track is a generic term for a grid row. · 9/28 Grid lines are the horizontal and vertical dividing lines of the grid. · grid column or Grid cell is the space between two adjacent row and two adjacent column grid lines. · Grid area is the logical space used to lay out one or more grid items. It is bound by four grid lines, one on each side of the grid area. ·

Slide 10

Slide 10

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

C o n c e p t s #cssgrid #blinkon #igalia Grid cell is the space between two adjacent row and two adjacent column grid lines. · 10/28 Grid lines are the horizontal and vertical dividing lines of the grid. · Grid track is a generic term for a grid column or grid row. · Grid area is the logical space used to lay out one or more grid items. It is bound by four grid lines, one on each side of the grid area. ·

Slide 11

Slide 11

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

C o n c e p t s #cssgrid #blinkon #igalia Grid area is the logical space used to lay out one or more grid items. It is bound by four grid lines, one on each side of the grid area. · 11/28 Grid lines are the horizontal and vertical dividing lines of the grid. · Grid track is a generic term for a grid column or grid row. · Grid cell is the space between two adjacent row and two adjacent column grid lines. ·

Slide 12

Slide 12

C S S

G r i d

L a y o u t

|

S y n t a x #cssgrid #blinkon #igalia

. 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 ;

} C S S display: grid : De�nes 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> H T M L 12/28

Slide 13

Slide 13

T i t l e M e n u F o o t e r M a i n 2 0 0 p x 1 f r 1 0 0 p x 1 f r a u t o C S S

G r i d

L a y o u t

|

T r a c k

B r e a d t h s #cssgrid #blinkon #igalia Options : · length percentage �ex ( f r

  • free space - unit) m a x

c o n t e n t m i n

c o n t e n t m i n m a x ( m i n ,

m a x ) a u t o

13/28

Slide 14

Slide 14

T i t l e M e n u F o o t e r M a i n 2 0 0 p x 1 f r 1 0 0 p x 1 f r a u t o C S S

G r i d

L a y o u t

|

F l e x i b l e

T r a c k

B r e a d t h s #cssgrid #blinkon #igalia Flexible track breadths will grow or shrink and automatically adapt themselves to viewport size. · 14/28

Slide 15

Slide 15

T i t l e M e n u F o o t e r M a i n 2 0 0 p x 1 f r 1 0 0 p x 1 f r a u t o C S S

G r i d

L a y o u t

|

F l e x i b l e

T r a c k

B r e a d t h s #cssgrid #blinkon #igalia This allows to create very customized grids , de�ning �exible tracks with minimum and maximum breadths depending on their contents or the available free space left by the rest of tracks and viewport size. · 15/28

Slide 16

Slide 16

T i t l e M e n u F o o t e r M a i n C S S

G r i d

L a y o u t

|

R e s p o n s i v e

L a y o u t #cssgrid #blinkon #igalia CSS Grid Layout can be used combined with other CSS features to create responsive designs . For example previous case can be adapted to portrait mode if the screen orientation changes using Media Queries . · · 16/28

Slide 17

Slide 17

C S S

G r i d

L a y o u t

|

R e s p o n s i v e

L a y o u t #cssgrid #blinkon #igalia

@ m e d i a

( o r i e n t a t i o n :

p o r t r a i t )

{

. g r i d

{

g r i d

t e m p l a t e

c o l u m n s :

a u t o

1 f r ;

g r i d

t e m p l a t e

r o w s :

a u t o

1 f r

a u t o ;

}

. t i t l e

{

g r i d

c o l u m n :

1 ;

g r i d

r o w :

1 ;

}

. m e n u

{

g r i d

c o l u m n :

2 ;

g r i d

r o w :

1 ;

}

. m a i n

{

g r i d

c o l u m n :

1

/

s p a n

2 ;

g r i d

r o w :

2 ;

}

. f o o t e r

{

g r i d

c o l u m n :

1

/

s p a n

2 ;

g r i d

r o w :

3 ;

}

} C S S Change g r i d

t e m p l a t e

c o l u m n s and g r i d

t e m p l a t e

r o w s . Change position inside the grid of the di�erent items. · · 17/28

Slide 18

Slide 18

C S S

G r i d

L a y o u t

|

E x a m p l e s #cssgrid #blinkon #igalia Enable experimental Web Platform features :

chrome://�ags/#enable-experimental-web-platform-features GitHub repository with di�erent examples:

http://igalia.github.io/css-grid-layout/ Video :

https://www.youtube.com/watch?v=nsWtMN54bEI · · Responsive grid :

http://igalia.github.io/css-grid-layout/responsive-grid.html Gallery :

http://igalia.github.io/css-grid-layout/gallery.html

· 18/28

Slide 19

Slide 19

C S S

G r i d

L a y o u t

|

A r e a s

&

A l i g n m e n t #cssgrid #blinkon #igalia

. g r i d

{

d i s p l a y :

g r i d ;

g r i d

t e m p l a t e

a r e a s :

" t i t l e

t i t l e

t i t l e

s o c i a l "

" m e n u

m a i n

m a i n

s o c i a l "

" m e n u

m a i n

m a i n

s o c i a l "

" f o o t e r

f o o t e r

f o o t e r

f o o t e r " ;

}

. t i t l e

{

g r i d

a r e a :

t i t l e ;

a l i g n

s e l f :

c e n t e r ;

j u s t i f y

s e l f :

c e n t e r ;

}

. m e n u

{

g r i d

a r e a :

m e n u ;

a l i g n

s e l f :

s t a r t ;

}

. m a i n

{

g r i d

a r e a :

m a i n ;

}

. s o c i a l

{

g r i d

a r e a :

s o c i a l ;

a l i g n

s e l f :

e n d ;

j u s t i f y

s e l f :

r i g h t ;

}

. f o o t e r

{

g r i d

a r e a :

f o o t e r ;

a l i g n

s e l f :

s t a r t ;

}

C S S g r i d

t e m p l a t e

a r e a s speci�es named grid areas that can be referenced to position grid items. Follows CSS Box Alignment spec for alignment features. · · 19/28

Slide 20

Slide 20

C S S

G r i d

L a y o u t

|

A r e a s

&

A l i g n m e n t T i t l e M e n u F o o t e r M a i n S o c i a l #cssgrid #blinkon #igalia 20/28

Slide 21

Slide 21

C S S

G r i d

L a y o u t

|

A u t o

p l a c e m e n t #cssgrid #blinkon #igalia

f o r m

{

d i s p l a y :

g r i d ;

g r i d

a u t o

f l o w :

r o w ;

}

l a b e l

{

g r i d

c o l u m n :

1 ;

}

i n p u t ,

t e x t a r e a

{

g r i d

c o l u m n :

2 ;

}

. c o n t r o l s

{

g r i d

c o l u m n :

1

/

s p a n

2 ;

}

C S S Grid items can be positioned outside of the grid bounds. This causes the grid container to generate implicit grid tracks, forming the implicit grid . g r i d

a u t o

f l o w controls the direction in which the grid items are automatically placed. · · 21/28

Slide 22

Slide 22

C S S

G r i d

L a y o u t

|

A u t o

p l a c e m e n t L a b e l C o n t r o l s F o r m

F i e l d L a b e l F o r m

F i e l d L a b e l F o r m

F i e l d L a b e l F o r m

F i e l d #cssgrid #blinkon #igalia 22/28

Slide 23

Slide 23

C S S

G r i d

L a y o u t

|

C u r r e n t

s t a t u s #cssgrid #blinkon #igalia Spec (W3C Working Draft, 23 January 2014): http://www.w3.org/TR/css-grid-1/ . Main browsers: · · Old version already shipped in IE/Trident . Work in progress in Chromium/Blink (Google and Igalia) and Safari/WebKit (Igalia). Mozilla has started the development in Firefox/Gecko early this year. · · · 23/28

Slide 24

Slide 24

C S S

G r i d

L a y o u t

|

I m p l e m e n t a t i o n

S t a t u s #cssgrid #blinkon #igalia De�ne grids using all di�erent properties in the spec. Support for named grid lines and named grid areas . All placement options are supported too (both explicit and implicit grid). Track sizing and auto-placement algorithms are already implemented. · · · · 24/28

Slide 25

Slide 25

C S S

G r i d

L a y o u t

|

R o a d m a p #cssgrid #blinkon #igalia Subgrids (still under discussion inside the CSS WG). Alignment. Fragmentation. Test coverage. Performance optimizations. Support for di�erent writing modes. Selection. · · · · · · · 25/28

Slide 26

Slide 26

A c k n o w l e d g e m e n t s #cssgrid #blinkon #igalia Bloomberg is sponsoring our work in CSS Grid Layout. · 26/28

Slide 27

Slide 27

T h a n k

Y o u ! i g a l i a . c o m / b r o w s e r s g+ google.com/+ManuelRegoCasasnovas

twitter @regocasasnovas

www people.igalia.com/mrego/

github github.com/mrego

Slide 28

Slide 28