What’s Grid? CSS Grid Layout is a CSS layout method designed for the two-dimensional layout of items on a webpage or application. Rachel Andrew
Slide 4
Basic grid
Slide 5
What’s this?
Slide 6
What’s this?
Slide 7
What’s this?
Slide 8
What’s this?
Slide 9
Example HTML
Slide 10
So what’s new?
•
display: grid
•
grid-template-columns/grid-template-rows
•
grid-gap
Where the magic happens. All children to grid items
The number and size of the columns/rows. There’s shorthand syntax…but I wont use it
Essentially the margin between cells. You’ll know gutter if you have used a grid framework before.
Slide 11
That’s interesting… if you’re making a static gallery Lets look at new units and CSS functions and make our grid fluid
Slide 12
New unit on the block, fraction (fr)
Slide 13
Setting up rows and columns is repetitive If we had a lot more columns than we are currently making, this will get painful. Enter repeat.
Slide 14
repeat()
Slide 15
Cells could get tiny, so minmax() Sets the sizes no smaller than the min and no greater than the max. You can get a long way with this without needing media queries!
Slide 16
minmax()
Slide 17
All together now You aren’t limited to just one of the units we have discussed. You can mix them all together.
Slide 18
All together now
Slide 19
Row/Column further reading •
grid-column: span
•
grid-template-column: auto/auto-fit
•
grid-auto-rows/columns
You can define how many columns to span
Enables a lot of responsiveness without media queries
Create implicit grid tracks
Slide 20
Positioning areas
Slide 21
Positioning areas
Slide 22
Grid column/row
Slide 23
Overlap 1
2
3
4
2
3
4
5
Slide 24
The holy grail at least it was.
Slide 25
The holy grail
Slide 26
We can do better the numbering can be tricky, naming is a nicer option
Slide 27
The named holy grail
Slide 28
Responsive
Slide 29
Named lines You can name each line in a row or column
Slide 30
Named lines
Slide 31
Named lines
Slide 32
Named lines
Slide 33
Support It’s not bad
Slide 34
Use in production •
There’s no Polyfill
•
@supports(display: grid)
•
JS load a fallback
Grid is too complex
Fallback will likely be Flex - depends on your project
There’s efficiency to be gained Stripe does this, but…
Slide 35
Further Reading
•
Rachel Andrew
•
gridbyexample.com/
•
Wes Bos is releasing a grid course
•
mozilladevelopers.github.io/playground/
anything - book, talks, blogs, but especially:
Slide 36
Thank you Examples on CodePen: https://codepen.io/collection/nLxmgY/