SlideShare una empresa de Scribd logo
1 de 71
Descargar para leer sin conexión
Introducing

CSS Grid Layout
Rachel Andrew
HTML 5j Web Platform Division, Tokyo
Rachel Andrew
CSS Working Group Invited Expert
Google Developer Expert for Web Technologies
Co-founder Perch CMS: https://grabaperch.com
Contact: me@rachelandrew.co.uk
rachelandrew.co.uk
@rachelandrew
Defining a Grid
Defining a Grid
- display: grid;
- display: inline-grid;
With a grid defined on the
parent element, all direct
children become Grid
Items.
.cards {
display: grid;
}
Defining a Grid
- grid-template-columns
- grid-template-rows
With these properties we
define an explicit grid. This
one has 3 column tracks
and 3 row tracks.
http://cssgrid.me/05161
.cards {
display: grid;
grid-template-columns: 250px 250px 250px;
grid-template-rows: 200px 200px 200px;
}
Defining a Grid
- grid-column-gap
- grid-row-gap
- grid-gap
We can create a gap
between rows and
columns. This gap acts
much like column-gap in
multiple column layout.
http://cssgrid.me/05162
.cards {
display: grid;
grid-template-columns: 250px 250px 250px;
grid-template-rows: 200px 200px 200px;
grid-gap: 20px;
}
Defining a Grid
The fr unit is a fraction
unit, representing a
fraction of the available
space in the container.
I have created 3 equal
width columns, each 1
fraction of the available
space.
.cards {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 200px 200px 200px;
grid-gap: 20px;
}
Defining a Grid
The fr unit is a fraction
unit, representing a
fraction of the available
space in the container.
We have created 3
columns, the units add up
to 4. The space is spilt into
4 equal parts, the first 2
tracks are given 1 part, the
fine track 2 parts.
.cards {
display: grid;
grid-template-columns: 1fr 1fr 2fr;
grid-template-rows: 200px 200px 200px;
grid-gap: 20px;
}
Defining a Grid
The fr unit is a fraction
unit, representing a
fraction of the available
space in the container.
You can mix fraction units
with other length units.
Any tracks with a fraction
unit share the space left
after fixed size tracks and
the gaps have been
defined.
http://cssgrid.me/05164
.cards {
display: grid;
grid-template-columns: 500px 1fr 2fr;
grid-template-rows: 200px 200px 200px;
grid-gap: 20px;
}
Defining a Grid
The repeat syntax lets us
define a repeating pattern
of tracks.
Here we are creating 3 1fr
column tracks.
http://cssgrid.me/05165
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 200px 200px 200px;
grid-gap: 20px;
}
Defining a Grid
The explicit grid is the one
we define with rows and
columns. If we didn’t define
rows however grid would
great implicit row tracks
for us.
These will be auto sized by
default.
http://cssgrid.me/05166
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
}
Defining a Grid
We can define the size of
implicit rows and column
with the properties:
- grid-auto-rows
- grid-auto-columns
http://cssgrid.me/05167
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: 200px;
grid-gap: 20px;
}
Defining a Grid
Use the auto-fill keyword
and grid will create as
many tracks that will fit
into the container.
http://cssgrid.me/05168
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, 200px);
grid-gap: 20px;
}
Defining a Grid
The minmax() function
enables the creation of
flexible grids. The first
value is the minimum size
of the Grid Track, the
second the max size - set
that to 1fr to allow the
track to take up remaining
space.
http://cssgrid.me/05169
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px,1fr));
grid-gap: 20px;
}
Placing Items on the Grid
Grid Track
A Grid Track is the space between two
Grid Lines. Tracks can be horizontal or
vertical (rows or columns).
The highlighted Grid Track is between
Row Lines 2 and 3.
Grid Lines
Lines can be horizontal or vertical. They
are referred to by number and can be
named.
Highlighted is Column Line 2.
Grid lines relate to writing mode. In
a right to left language such as
Arabic the first column line is the
right-hand line.
Grid Cell
The smallest unit on our grid, a Grid Cell
is the space between four Grid Lines. It’s
just like a table cell.
The highlighted Grid Cell is between row
lines 2 and 3 and column lines 2 and 3.
Grid Area
Any area of the Grid bound by 4 Grid
Lines. It can contain many Grid Cells.
The highlighted Grid Area is between
row lines 1 and 3, column lines 2 and 4.
Using line numbers
I have created a grid with 3
column tracks and 2 row
tracks.
With no placement our
blocks lay out one per grid
cell.
.cards {
display: grid;
grid-gap: 20px;
grid-template-columns: repeat(3,1fr);
grid-auto-rows: 200px;
}
1 2 3
Using line numbers
To place an item on the grid
I specify start and end lines
using new properties:
- grid-column-start
- grid-column-end
- grid-row-start
- grid-row-end
.card:nth-child(1) {
grid-column-start: 2;
grid-column-end: 4;
grid-row-start: 1;
grid-row-end: 3;
}
1
2
3
Using line numbers
These can be expressed as
a shorthand:
- grid-column
- grid-row
http://cssgrid.me/051614
.card:nth-child(1) {
grid-column: 2 / 4;
grid-row: 1 / 3;
}
1
2
3
Using line numbers
They can be expressed as
one line using grid-area,
the order of the values is:
- grid-row-start
- grid-column-start
- grid-row-end
- grid-column-end
.card:nth-child(1) {
grid-area: 1 / 2 / 3 / 4;
}
1
2
3
Using line names
We name lines when
creating the grid. The name
goes in square brackets.
.cards {
display: grid;
grid-gap: 20px;
grid-template-columns: [side-start] 1fr
[main-start] 1fr 1fr
[main-end];
grid-template-rows: [main-start] 200px 200px
[main-end];
}
Using line names
Use the name instead of
the line number as the
value of the placement
properties.
http://cssgrid.me/051616
.card:nth-child(1) {
grid-column: main-start / main-end;
grid-row: main-start / main-end;
}
Lines define Grid Areas
By creating lines named
main-start and end for
rows and columns, grid has
created me a named grid
area called ‘main’.
I can use that to position
my element rather than the
line numbers or names.
http://cssgrid.me/051617
.cards {
display: grid;
grid-gap: 20px;
grid-template-columns: [side-start] 1fr
[main-start] 1fr 1fr
[main-end];
grid-template-rows: [main-start] 200px 200px
[main-end];
}
.card:nth-child(1) {
grid-area: main;
}
Defining Grid Areas
This time I haven’t named
my lines, I’ve just given
each element a name.
.card:nth-child(1) {
grid-area: main;
}
.card:nth-child(2) {
grid-area: side1;
}
.card:nth-child(3) {
grid-area: side2;
}
grid-template-areas
I then use these names to
describe my layout as the
value of grid-template-
areas.
http://cssgrid.me/051618
.cards {
display: grid;
grid-gap: 20px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 200px 200px;
grid-template-areas: "side1 main main"
"side2 main main";
}
mainside1
side2
main
main main
Grid Item Placement Algorithm
http://dev.w3.org/csswg/css-grid/#grid-item-placement-algorithm
“The following grid item placement
algorithm resolves automatic positions of
grid items into definite positions, ensuring
that every grid item has a well-defined grid
area to lay out into.”
A list containing images.
The landscape images are
inside a list item with a
class of ‘landscape’.
<ul class="wrapper">
<li><h3>1.</h3>
<img src="gallery1.jpg" alt="Balloons"></li>
<li class="landscape"><h3>2.</h3>
<img src="gallery2.jpg" alt="Balloons"></li>
<li class="landscape"><h3>3.</h3>
<img src="gallery8.jpg" alt="Balloons"></li>
<li><h3>4.</h3>
<img src="gallery4.jpg" alt="Balloons"></li>
<li><h3>7.</h3>
<img src="gallery5.jpg" alt="Balloons"></li>
<li class="landscape"><h3>6.</h3>
<img src="gallery6.jpg" alt="Balloons"></li>
<li><h3>7.</h3>
<img src="gallery9.jpg" alt="Balloons"></li>
</ul>
I have created a grid of
four equal columns.
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
When using automatic
placement we can create
rules for items in our
document - for example
displaying portrait and
landscape images
differently.
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
.landscape {
grid-column-end: span 2;
}
grid-auto-flow
The default value of grid-auto-flow is
sparse. Grid will move forward placing
items skipping cells if items do not fit .
With a dense packing
mode grid will move items
out of source order to
backfill spaces.
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-auto-flow: dense;
}
.landscape {
grid-column-end: span 2;
}
grid-auto-flow
With grid-auto-flow dense items are
displayed out of source order. Grid
backfills any suitable gaps.
http://cssgrid.me/051626
Grid and Accessibility
Power and responsibility
• Good = creating the most accessible source
order and using Grid or Flexbox to get the
optimal display for each device.
• Bad = using Grid or Flexbox as an excuse to
forget about the source.
• Terrible - stripping out semantic elements to
make everything a grid or flex item.
https://www.w3.org/TR/css-grid-1/#placement-a11y
Correct source order is important for
speech, for sequential navigation (such
as keyboard navigation), and non-CSS
UAs such as search engines, tactile
browsers, etc. Grid placement only
affects the visual presentation!
http://adrianroselli.com/2015/10/html-source-order-vs-css-display-order.html
Léonie Watson | On CSS accessibility
and drinking tea | CSS Day 2016
https://vimeo.com/180566024
Also see: 

http://tink.uk/flexbox-the-keyboard-navigation-disconnect/
Is Grid a competing specification to Flexbox?
When should we use Grid instead of
Flexbox?
Flexbox is for 1 dimensional layout -
a column OR a row.
Grid is for 2 dimensional layout -
both columns AND rows.
Wrapping list items using
flexbox.
.flex {
display: flex;
flex-wrap: wrap;
margin: 0 -10px;
}
.flex li {
flex: 1 1 200px;
margin: 10px;
}
Wrapping list items with
Grid Layout.
http://cssgrid.me/051629
.grid {
display: grid;
grid-template-columns:
repeat(auto-fill, minmax(200px 1fr));
grid-gap: 20px;
}
https://cssgrid.me/051634
Using the minmax()
function with grid-auto-
rows.
.home-hero {
display: grid;
grid-gap: 1px;
grid-auto-rows: minmax(150px, auto);
}
An item on the grid can
become a grid or flex
container itself.
In this case I am using
flexbox and auto margins
to push my content to the
bottom of the box.
.special {
display: flex;
flex-direction: column;
}
.special h3{
margin-top: auto;
}
Animatable
• grid-template-columns
• grid-template-rows
• grid-gap
• grid-column-gap
• grid-row-gap
https://drafts.csswg.org/css-grid/#track-sizing
grid-template-* animatable as a simple list
of length, percentage, or calc, provided the
only differences are the values of the length,
percentage, or calc components in the list.
https://drafts.csswg.org/css-grid/#gutters
grid-gap, grid-column-gap, grid-row-gap
animatable as length, percentage, or calc.
March 2017 March 2017 March 2017 March 2017 March 2017 Soon!
But, what about browsers with 

no support?
CSS Feature Queries
http://caniuse.com/#feat=css-featurequeries
A feature query looks like
a media query.
Test for a property and
value pair.
// code for non-grid browsers
@supports (display: grid) {
// grid layout code here
}
To use feature queries
• Write CSS for browsers without support
• Override those properties inside the feature
queries
• See https://hacks.mozilla.org/2016/08/using-
feature-queries-in-css/
https://cssgrid.me/051635
You don’t have to turn your entire layout
over to grid. Look at using it for small UI
elements, as an enhancement.
More code plus video tutorials!
I am creating a list of examples, video tutorials and information at:
http://gridbyexample.com
Think of a question later? AMA.
https://github.com/rachelandrew/cssgrid-ama
Thank you!
https://rachelandrew.co.uk/speaking/event/html5j-japan


@rachelandrew

Más contenido relacionado

La actualidad más candente

Render Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout TodayRender Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout TodayRachel Andrew
 
Talk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid LayoutTalk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid LayoutRachel Andrew
 
Laracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxRachel Andrew
 
CSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart OrlandoCSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart OrlandoRachel Andrew
 
Confoo: The New CSS Layout
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS LayoutRachel Andrew
 
What I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridRachel Andrew
 
New CSS Meets the Real World
New CSS Meets the Real WorldNew CSS Meets the Real World
New CSS Meets the Real WorldRachel Andrew
 
Introduction to CSS Grid Layout
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid LayoutRachel Andrew
 
Making the most of New CSS Layout
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS LayoutRachel Andrew
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
 
An Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real WorldAn Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real WorldRachel Andrew
 
An Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid LayoutAn Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid LayoutRachel Andrew
 
CSS Grid Layout: An Event Apart Boston 2016
CSS Grid Layout: An Event Apart Boston 2016CSS Grid Layout: An Event Apart Boston 2016
CSS Grid Layout: An Event Apart Boston 2016Rachel Andrew
 
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...Igalia
 
The Right Layout Tool for the Job
The Right Layout Tool for the JobThe Right Layout Tool for the Job
The Right Layout Tool for the JobRachel Andrew
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatRachel Andrew
 

La actualidad más candente (20)

Render Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout TodayRender Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout Today
 
Talk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid LayoutTalk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid Layout
 
Next-level CSS
Next-level CSSNext-level CSS
Next-level CSS
 
Laracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and Flexbox
 
CSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart OrlandoCSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart Orlando
 
Confoo: The New CSS Layout
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS Layout
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 
What I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS Grid
 
New CSS Meets the Real World
New CSS Meets the Real WorldNew CSS Meets the Real World
New CSS Meets the Real World
 
Introduction to CSS Grid Layout
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid Layout
 
Making the most of New CSS Layout
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS Layout
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
An Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real WorldAn Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real World
 
CSS Grid
CSS GridCSS Grid
CSS Grid
 
An Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid LayoutAn Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid Layout
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
 
CSS Grid Layout: An Event Apart Boston 2016
CSS Grid Layout: An Event Apart Boston 2016CSS Grid Layout: An Event Apart Boston 2016
CSS Grid Layout: An Event Apart Boston 2016
 
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
 
The Right Layout Tool for the Job
The Right Layout Tool for the JobThe Right Layout Tool for the Job
The Right Layout Tool for the Job
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
 

Similar a CSS Grid for html5j

DevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayRachel Andrew
 
Devoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid LayoutDevoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid LayoutRachel Andrew
 
An Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid LayoutAn Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid LayoutRachel Andrew
 
CSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzRachel Andrew
 
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgRachel Andrew
 
The Grid - The Future of CSS Layout
The Grid - The Future of CSS LayoutThe Grid - The Future of CSS Layout
The Grid - The Future of CSS LayoutRonny Siikaluoma
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSRachel Andrew
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Rachel Andrew
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid LayoutRachel Andrew
 
View Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsView Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsRachel Andrew
 
An Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldRachel Andrew
 
Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Rachel Andrew
 
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...Igalia
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Rachel Andrew
 
Solving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsSolving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsFITC
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSRachel Andrew
 

Similar a CSS Grid for html5j (20)

CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 
World of CSS Grid
World of CSS GridWorld of CSS Grid
World of CSS Grid
 
DevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout today
 
Devoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid LayoutDevoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid Layout
 
An Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid LayoutAn Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid Layout
 
CSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, Linz
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf Freiburg
 
The Grid - The Future of CSS Layout
The Grid - The Future of CSS LayoutThe Grid - The Future of CSS Layout
The Grid - The Future of CSS Layout
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
 
View Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsView Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & Friends
 
An Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real World
 
Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17
 
17523630.ppt
17523630.ppt17523630.ppt
17523630.ppt
 
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17
 
Solving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsSolving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and Friends
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJS
 

Más de Rachel Andrew

All Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutRachel Andrew
 
SmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutRachel Andrew
 
Unlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutRachel Andrew
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSSRachel Andrew
 
Into the Weeds of CSS Layout
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS LayoutRachel Andrew
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & FriendsRachel Andrew
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp KeynoteRachel Andrew
 
New CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldRachel Andrew
 
Perch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersRachel Andrew
 
Evergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersRachel Andrew
 
Where does CSS come from?
Where does CSS come from?Where does CSS come from?
Where does CSS come from?Rachel Andrew
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Rachel Andrew
 

Más de Rachel Andrew (13)

All Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid Layout
 
SmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid Layout
 
Unlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid Layout
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
 
Into the Weeds of CSS Layout
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS Layout
 
Graduating to Grid
Graduating to GridGraduating to Grid
Graduating to Grid
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp Keynote
 
New CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real World
 
Perch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
 
Evergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsers
 
Where does CSS come from?
Where does CSS come from?Where does CSS come from?
Where does CSS come from?
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
 

Último

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Último (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

CSS Grid for html5j

  • 1. Introducing
 CSS Grid Layout Rachel Andrew HTML 5j Web Platform Division, Tokyo
  • 2. Rachel Andrew CSS Working Group Invited Expert Google Developer Expert for Web Technologies Co-founder Perch CMS: https://grabaperch.com Contact: me@rachelandrew.co.uk rachelandrew.co.uk @rachelandrew
  • 4. Defining a Grid - display: grid; - display: inline-grid; With a grid defined on the parent element, all direct children become Grid Items. .cards { display: grid; }
  • 5. Defining a Grid - grid-template-columns - grid-template-rows With these properties we define an explicit grid. This one has 3 column tracks and 3 row tracks. http://cssgrid.me/05161 .cards { display: grid; grid-template-columns: 250px 250px 250px; grid-template-rows: 200px 200px 200px; }
  • 6. Defining a Grid - grid-column-gap - grid-row-gap - grid-gap We can create a gap between rows and columns. This gap acts much like column-gap in multiple column layout. http://cssgrid.me/05162 .cards { display: grid; grid-template-columns: 250px 250px 250px; grid-template-rows: 200px 200px 200px; grid-gap: 20px; }
  • 7. Defining a Grid The fr unit is a fraction unit, representing a fraction of the available space in the container. I have created 3 equal width columns, each 1 fraction of the available space. .cards { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 200px 200px 200px; grid-gap: 20px; }
  • 8. Defining a Grid The fr unit is a fraction unit, representing a fraction of the available space in the container. We have created 3 columns, the units add up to 4. The space is spilt into 4 equal parts, the first 2 tracks are given 1 part, the fine track 2 parts. .cards { display: grid; grid-template-columns: 1fr 1fr 2fr; grid-template-rows: 200px 200px 200px; grid-gap: 20px; }
  • 9. Defining a Grid The fr unit is a fraction unit, representing a fraction of the available space in the container. You can mix fraction units with other length units. Any tracks with a fraction unit share the space left after fixed size tracks and the gaps have been defined. http://cssgrid.me/05164 .cards { display: grid; grid-template-columns: 500px 1fr 2fr; grid-template-rows: 200px 200px 200px; grid-gap: 20px; }
  • 10. Defining a Grid The repeat syntax lets us define a repeating pattern of tracks. Here we are creating 3 1fr column tracks. http://cssgrid.me/05165 .cards { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: 200px 200px 200px; grid-gap: 20px; }
  • 11. Defining a Grid The explicit grid is the one we define with rows and columns. If we didn’t define rows however grid would great implicit row tracks for us. These will be auto sized by default. http://cssgrid.me/05166 .cards { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 20px; }
  • 12. Defining a Grid We can define the size of implicit rows and column with the properties: - grid-auto-rows - grid-auto-columns http://cssgrid.me/05167 .cards { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 200px; grid-gap: 20px; }
  • 13. Defining a Grid Use the auto-fill keyword and grid will create as many tracks that will fit into the container. http://cssgrid.me/05168 .cards { display: grid; grid-template-columns: repeat(auto-fill, 200px); grid-gap: 20px; }
  • 14. Defining a Grid The minmax() function enables the creation of flexible grids. The first value is the minimum size of the Grid Track, the second the max size - set that to 1fr to allow the track to take up remaining space. http://cssgrid.me/05169 .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); grid-gap: 20px; }
  • 15. Placing Items on the Grid
  • 16. Grid Track A Grid Track is the space between two Grid Lines. Tracks can be horizontal or vertical (rows or columns). The highlighted Grid Track is between Row Lines 2 and 3.
  • 17. Grid Lines Lines can be horizontal or vertical. They are referred to by number and can be named. Highlighted is Column Line 2.
  • 18. Grid lines relate to writing mode. In a right to left language such as Arabic the first column line is the right-hand line.
  • 19. Grid Cell The smallest unit on our grid, a Grid Cell is the space between four Grid Lines. It’s just like a table cell. The highlighted Grid Cell is between row lines 2 and 3 and column lines 2 and 3.
  • 20. Grid Area Any area of the Grid bound by 4 Grid Lines. It can contain many Grid Cells. The highlighted Grid Area is between row lines 1 and 3, column lines 2 and 4.
  • 21. Using line numbers I have created a grid with 3 column tracks and 2 row tracks. With no placement our blocks lay out one per grid cell. .cards { display: grid; grid-gap: 20px; grid-template-columns: repeat(3,1fr); grid-auto-rows: 200px; } 1 2 3
  • 22. Using line numbers To place an item on the grid I specify start and end lines using new properties: - grid-column-start - grid-column-end - grid-row-start - grid-row-end .card:nth-child(1) { grid-column-start: 2; grid-column-end: 4; grid-row-start: 1; grid-row-end: 3; } 1 2 3
  • 23. Using line numbers These can be expressed as a shorthand: - grid-column - grid-row http://cssgrid.me/051614 .card:nth-child(1) { grid-column: 2 / 4; grid-row: 1 / 3; } 1 2 3
  • 24. Using line numbers They can be expressed as one line using grid-area, the order of the values is: - grid-row-start - grid-column-start - grid-row-end - grid-column-end .card:nth-child(1) { grid-area: 1 / 2 / 3 / 4; } 1 2 3
  • 25. Using line names We name lines when creating the grid. The name goes in square brackets. .cards { display: grid; grid-gap: 20px; grid-template-columns: [side-start] 1fr [main-start] 1fr 1fr [main-end]; grid-template-rows: [main-start] 200px 200px [main-end]; }
  • 26. Using line names Use the name instead of the line number as the value of the placement properties. http://cssgrid.me/051616 .card:nth-child(1) { grid-column: main-start / main-end; grid-row: main-start / main-end; }
  • 27. Lines define Grid Areas By creating lines named main-start and end for rows and columns, grid has created me a named grid area called ‘main’. I can use that to position my element rather than the line numbers or names. http://cssgrid.me/051617 .cards { display: grid; grid-gap: 20px; grid-template-columns: [side-start] 1fr [main-start] 1fr 1fr [main-end]; grid-template-rows: [main-start] 200px 200px [main-end]; } .card:nth-child(1) { grid-area: main; }
  • 28. Defining Grid Areas This time I haven’t named my lines, I’ve just given each element a name. .card:nth-child(1) { grid-area: main; } .card:nth-child(2) { grid-area: side1; } .card:nth-child(3) { grid-area: side2; }
  • 29. grid-template-areas I then use these names to describe my layout as the value of grid-template- areas. http://cssgrid.me/051618 .cards { display: grid; grid-gap: 20px; grid-template-columns: repeat(3, 1fr); grid-template-rows: 200px 200px; grid-template-areas: "side1 main main" "side2 main main"; } mainside1 side2 main main main
  • 30. Grid Item Placement Algorithm
  • 31. http://dev.w3.org/csswg/css-grid/#grid-item-placement-algorithm “The following grid item placement algorithm resolves automatic positions of grid items into definite positions, ensuring that every grid item has a well-defined grid area to lay out into.”
  • 32. A list containing images. The landscape images are inside a list item with a class of ‘landscape’. <ul class="wrapper"> <li><h3>1.</h3> <img src="gallery1.jpg" alt="Balloons"></li> <li class="landscape"><h3>2.</h3> <img src="gallery2.jpg" alt="Balloons"></li> <li class="landscape"><h3>3.</h3> <img src="gallery8.jpg" alt="Balloons"></li> <li><h3>4.</h3> <img src="gallery4.jpg" alt="Balloons"></li> <li><h3>7.</h3> <img src="gallery5.jpg" alt="Balloons"></li> <li class="landscape"><h3>6.</h3> <img src="gallery6.jpg" alt="Balloons"></li> <li><h3>7.</h3> <img src="gallery9.jpg" alt="Balloons"></li> </ul>
  • 33. I have created a grid of four equal columns. .wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; }
  • 34.
  • 35. When using automatic placement we can create rules for items in our document - for example displaying portrait and landscape images differently. .wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; } .landscape { grid-column-end: span 2; }
  • 36. grid-auto-flow The default value of grid-auto-flow is sparse. Grid will move forward placing items skipping cells if items do not fit .
  • 37. With a dense packing mode grid will move items out of source order to backfill spaces. .wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; grid-auto-flow: dense; } .landscape { grid-column-end: span 2; }
  • 38. grid-auto-flow With grid-auto-flow dense items are displayed out of source order. Grid backfills any suitable gaps. http://cssgrid.me/051626
  • 40. Power and responsibility • Good = creating the most accessible source order and using Grid or Flexbox to get the optimal display for each device. • Bad = using Grid or Flexbox as an excuse to forget about the source. • Terrible - stripping out semantic elements to make everything a grid or flex item.
  • 41. https://www.w3.org/TR/css-grid-1/#placement-a11y Correct source order is important for speech, for sequential navigation (such as keyboard navigation), and non-CSS UAs such as search engines, tactile browsers, etc. Grid placement only affects the visual presentation!
  • 43. Léonie Watson | On CSS accessibility and drinking tea | CSS Day 2016 https://vimeo.com/180566024 Also see: 
 http://tink.uk/flexbox-the-keyboard-navigation-disconnect/
  • 44. Is Grid a competing specification to Flexbox?
  • 45. When should we use Grid instead of Flexbox?
  • 46. Flexbox is for 1 dimensional layout - a column OR a row. Grid is for 2 dimensional layout - both columns AND rows.
  • 47. Wrapping list items using flexbox. .flex { display: flex; flex-wrap: wrap; margin: 0 -10px; } .flex li { flex: 1 1 200px; margin: 10px; }
  • 48.
  • 49. Wrapping list items with Grid Layout. http://cssgrid.me/051629 .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px 1fr)); grid-gap: 20px; }
  • 50.
  • 51.
  • 53.
  • 54. Using the minmax() function with grid-auto- rows. .home-hero { display: grid; grid-gap: 1px; grid-auto-rows: minmax(150px, auto); }
  • 55. An item on the grid can become a grid or flex container itself. In this case I am using flexbox and auto margins to push my content to the bottom of the box. .special { display: flex; flex-direction: column; } .special h3{ margin-top: auto; }
  • 56.
  • 57. Animatable • grid-template-columns • grid-template-rows • grid-gap • grid-column-gap • grid-row-gap
  • 58. https://drafts.csswg.org/css-grid/#track-sizing grid-template-* animatable as a simple list of length, percentage, or calc, provided the only differences are the values of the length, percentage, or calc components in the list.
  • 60.
  • 61. March 2017 March 2017 March 2017 March 2017 March 2017 Soon!
  • 62. But, what about browsers with 
 no support?
  • 65. A feature query looks like a media query. Test for a property and value pair. // code for non-grid browsers @supports (display: grid) { // grid layout code here }
  • 66. To use feature queries • Write CSS for browsers without support • Override those properties inside the feature queries • See https://hacks.mozilla.org/2016/08/using- feature-queries-in-css/
  • 68. You don’t have to turn your entire layout over to grid. Look at using it for small UI elements, as an enhancement.
  • 69. More code plus video tutorials! I am creating a list of examples, video tutorials and information at: http://gridbyexample.com
  • 70. Think of a question later? AMA. https://github.com/rachelandrew/cssgrid-ama