The Dark Side of the Grid

A presentation at #a11yTO Conference in October 2018 in Toronto, ON, Canada by Manuel Matuzovic

Slide 1

Slide 1

Slide 2

Slide 2

Manuel Matuzović @mmatuzo Museum of Fine Arts, Museum of Natural History, Volksgarten und parliament in Vienna

Slide 3

Slide 3

The Dark Side of the Grid

Slide 4

Slide 4

CSS Grid Layout? CSS Grid Layout is a grid-based layout system designed for two-dimensional layouts. @mmatuzo

Slide 5

Slide 5

What’s special about Grid? The first true layout method in CSS. float, display:inline-block, position, display:table, display: flex not designed for building two-dimensional layouts. Kinda like table layouts but responsive and flexible and described in CSS and not in HTML @mmatuzo

Slide 6

Slide 6

Grid-related properties and values display justify-content grid-column grid-template-columns align-content grid-row grid-template-rows place-content grid-area grid-template-areas grid-auto-columns justify-self grid-template grid-auto-rows align-self grid-column-gap grid-auto-flow place-self grid-row-gap grid min-content, max-content, fitcontent grid-gap grid-column-start fr justify-items grid-column-end repeat() align-items grid-row-start minmax() place-items grid-row-end @mmatuzo

Slide 7

Slide 7

Cover of the LP “The Dark Side of the Moon” by Pink Floyd, released in 1973.

Slide 8

Slide 8

PINK FLOYD FUN FACT #1 45 million copie s sold The Dark Side of the Moon is, with over 45 million copies sold, the fourth best-selling album worldwide. #1 Thriller by Michael Jackson (66 Million) #2 Their Greatest Hits (1971–1975) by Eagles (51 Million) #3 Back in Black by AC/DC (50 Million) @mmatuzo

Slide 9

Slide 9

C H A N G I NG V I S U A L O R D E R @mmatuzo

Slide 10

Slide 10

Changing Visual Order Explicit placement order property Absolute positioning Auto flow Areas @mmatuzo

Slide 11

Slide 11

Visual Order Both the tab order and the order in which screen readers read content follow DOM order. Changing visual order in CSS has no effect on tab and screen reader order. @mmatuzo

Slide 12

Slide 12

Visual Order Visual order matches DOM order <1> <2> <3> <4> <5> <6> {1} {2} {3} {4} {5} {6} @mmatuzo

Slide 13

Slide 13

Visual Order Visual order matches DOM order <1> <2> <3> <4> <5> <6> {1} {2} {3} {4} {5} {6} Visual order doesn’t match DOM order <1> <2> <3> <4> <5> <6> {1} {4} {2} {6} {5} {3} @mmatuzo

Slide 14

Slide 14

V ISUAL O RDER EX PLIC IT PL A CE ME NT @mmatuzo

Slide 15

Slide 15

Explicit Placement Grid gives us the ability to place items in every cell we want in our grids by specifying in which column and row they start or end. grid-column grid-row grid-column-start grid-row-start grid-column-end grid-row-end @mmatuzo

Slide 16

Slide 16

$ explicit placement .item:nth-child(1) { .item:nth-child(2) { grid-column: 2; grid-column: 3; grid-row: 2; grid-row: 3; } } ""... @mmatuzo

Slide 17

Slide 17

V ISUAL O RDER A R E A S @mmatuzo

Slide 18

Slide 18

Example: Mobile layout

Slide 19

Slide 19

$ areas body { display: grid; grid-template-areas: "header" "content" "ads" "newsletter" "footer"; } @mmatuzo

Slide 20

Slide 20

$ areas body { display: grid; grid-template-areas: "header" "content" "ads" "newsletter" "footer"; } @mmatuzo

Slide 21

Slide 21

$ areas body { display: grid; grid-template-areas: "header" "newsletter" "content" "ads" "footer"; } @mmatuzo

Slide 22

Slide 22

https://s.codepen.io/matuzo/debug/ZMLpML @mmatuzo

Slide 23

Slide 23

$ areas body { grid-template-columns: 1fr 1fr; grid-template-areas: "header header" "content content" "ads newsletter" "footer footer"; } @mmatuzo

Slide 24

Slide 24

PINK FLOYD FUN FACT #2 73 6 weeks on the Billboard chart The Dark Side of The Moon spent 736 weeks on the Billboard chart. That’s more than 14 years! @mmatuzo

Slide 25

Slide 25

C O MPR O MISIN G O N S EM AN TICS @mmatuzo

Slide 26

Slide 26

“ I believe there will be a strong temptation, especially with Grid, to flatten out document structure in order that all elements become a child of the element with the Grid declared. Making layout simple, but at what cost? ” Rachel Andrew (rachelandrew.co.uk/archives/2015/07/28/modern-css-layout-power-and-responsibility)

Slide 27

Slide 27

$ compromising on semantics <form> <div> <label for="name">What's your name?!</label> <input type="text" id="name" !/> !</div> <div> <label for="email">E-Mail!</label> <input type="email" id="email" !/> !</div> !!... @mmatuzo

Slide 28

Slide 28

$ compromising on semantics … <fieldset> <legend>Shirt size!</legend> <div> <input type="radio" id="s" name="r"> <label for="s">S!</label> !</div> <div> <input type="radio" id="m" name="r"> <label for="m">M!</label> !</div> !</fieldset> !</form> @mmatuzo

Slide 29

Slide 29

https://s.codepen.io/matuzo/pen/BOWYLB?editors=1100 @mmatuzo

Slide 30

Slide 30

$ compromising on semantics form { display: grid; grid-template-columns: max-content minmax(auto, 600px); grid-gap: 10px 20px; } @mmatuzo

Slide 31

Slide 31

https://s.codepen.io/matuzo/pen/BOWYLB?editors=1100 @mmatuzo

Slide 32

Slide 32

$ compromising on semantics

<div> <label for="name">What's your name?!</label> <input type="text" id="name" !/> !</div> <div> <label for="email">E-Mail!</label> <input type="email" id="email" !/> !</div> @mmatuzo

Slide 33

Slide 33

$ compromising on semantics

<div> <label for="name">What's your name?!</label> <input type="text" id="name" !/> !</div> <div> <label for="email">E-Mail!</label> <input type="email" id="email" !/> !</div> @mmatuzo

Slide 34

Slide 34

$ compromising on semantics <fieldset> <legend strong>Shirt size!</legend strong> <div> <div> <input type="radio" id="s"> <label for="s">S!</label> !</div> <div> <input type="radio" id="m"> <label for="m">M!</label> !</div> !</div> !</fieldset> @mmatuzo

Slide 35

Slide 35

$ compromising on semantics <fieldset> <legend strong>Shirt size!</legend strong> <div> <div> <input type="radio" id="s"> <label for="s">S!</label> !</div> <div> <input type="radio" id="m"> <label for="m">M!</label> !</div> !</div> !</fieldset> @mmatuzo

Slide 36

Slide 36

https://s.codepen.io/matuzo/pen/BOWYLB?editors=1100 @mmatuzo

Slide 37

Slide 37

The form displayed without CSS

Slide 38

Slide 38

COMP ROM IS ING ON SE M ANTICS S U B GR I D @mmatuzo

Slide 39

Slide 39

“ A grid container that is itself a grid item can defer the definition of its rows and columns to its parent grid container, making it a subgrid. – https://drafts.csswg.org/css-grid-2/ ”

Slide 40

Slide 40

$ compromising on semantics form > div, fieldset { display: grid; grid-template-columns: subgrid; } @mmatuzo

Slide 41

Slide 41

Subgrid will ship with level 2 of the specification

Slide 42

Slide 42

“ display: contents causes an element's children to appear as if they were direct children of the element's parent, ignoring the element itself. https://caniuse.com/#search=contents ”

Slide 43

Slide 43

$ compromising on semantics form > div, fieldset { display: contents; } @mmatuzo

Slide 44

Slide 44

https://codepen.io/matuzo/pen/Mqrpbm @mmatuzo

Slide 45

Slide 45

display: contents; is supported by all major desktop browsers except for Edge

Slide 46

Slide 46

Due to a bug display: contents; removes items from the accessibility tree.

Slide 47

Slide 47

https://twitter.com/aardrian/status/1052027923786620928 @mmatuzo

Slide 48

Slide 48

PINK FLOYD FUN FACT #3 Mo nty Python and the Holy Grail In 1975 Pink Floyd helped to finance the movie “Monty Python and the Holy Grail” by the comedy group Monty Python. Some of the other investors were Led Zeppelin and Genesis. @mmatuzo

Slide 49

Slide 49

C RO S S B RO WSER S U PPO RT @mmatuzo

Slide 50

Slide 50

Grids History Microsoft shipped a Grid implementation behind the -ms- vendor prefix in IE 10 in 2011. Chrome, Firefox, Opera, Safari and Edge shipped a different implementation throughout 2017. @mmatuzo

Slide 51

Slide 51

$ browser support .grid { display: -ms-grid; -ms-grid-columns: 200px 200px; -ms-grid-rows: 130px 130px; display: grid; grid-template-columns: 200px 200px; grid-template-rows: 130px 130px; } @mmatuzo

Slide 52

Slide 52

Chrome IE 11 4 items in a 2 x 2 grid without explicit placement in Chrome and IE11

Slide 53

Slide 53

$ browser support .item:nth-child(1) { .item:nth-child(3) { -ms-grid-column: 1; -ms-grid-column: 1; -ms-grid-row: 1; -ms-grid-row: 2; } } .item:nth-child(2) { .item:nth-child(4) { } -ms-grid-column: 2; -ms-grid-column: 2; -ms-grid-row: 1; -ms-grid-row: 2; } @mmatuzo

Slide 54

Slide 54

4 items in a 2 x 2 grid with explicit placement in IE11

Slide 55

Slide 55

BRO WSER SUPP ORT A U T OP R E F I X E R ? @mmatuzo

Slide 56

Slide 56

$ autoprefixer module.exports = { plugins: [ require('autoprefixer')({ grid: true, }) ] } @mmatuzo

Slide 57

Slide 57

Autoprefixer with the grid setting set to true.

Slide 58

Slide 58

Autoprefixer with the grid setting set to true.

Slide 59

Slide 59

Autoprefixer fakes gaps by adding rows and columns in IE 10 and IE 11.

Slide 60

Slide 60

Autoprefixer fakes gaps by adding rows and columns in IE 10 and IE 11.

Slide 61

Slide 61

Autoprefixer gotchas grid-template or grid-template-areas + gridtemplate-columns mandatory for gap support. Area names must be unique. Negative line numbers, e.g. grid-column: 1 / -1; are not supported. @mmatuzo

Slide 62

Slide 62

Autoprefixer gotchas grid shorthand not supported. There are no named lines at the moment. It’s not possible to define end-lines only. No auto placement. @mmatuzo

Slide 63

Slide 63

Th ere is no d ar k sid e of t h e mo o n g r i d r e a l l y . M at te r of f ac t i t ' s al l da r k . PINK FLOYD: ECLIPSE @mmatuzo

Slide 64

Slide 64

Responsible use of Grid Avoid grid-template-areas or any other reordering techniques on interaction sensitive components. Test with your keyboard. Don’t compromise on semantics. @mmatuzo

Slide 65

Slide 65

Responsible use of Grid If you’re using autoprefixer make sure everyone in your team is aware of its limitations and what it does behind the scenes. Make sure your components work in older and less capable browsers. Embrace the power of progressive enhancement. @mmatuzo

Slide 66

Slide 66

Thank you ❤ Aaron Gustafson Scott O’Hara Adrian Roselli Eric Bailey Heydon Pickering Hidde de Vries Léonie Watson Steve Faulkner Oskar Westin Rob Dodson Billy Gregory @mmatuzo

Slide 67

Slide 67

Thank you manuel@matuzo.at @mmatuzo