SlideShare a Scribd company logo
Laying out the
future.
Rachel Andrew, ‹
CSSConf.asia 2016
Rachel Andrew
rachelandrew.co.uk
@rachelandrew
CSS Working Group Invited Expert
Google Developer Expert for Web Technologies
Co-founder Perch CMS: https://grabaperch.com
Contact: me@rachelandrew.co.uk
Modern CSS Layout?
‱ Floats
‱ Inline-block
‱ display: table
‱ Absolute & Relative positioning
‱ Frameworks 
 lots of frameworks
Our great hopes for layout
‱ Flexbox‹
https://drafts.csswg.org/css-flexbox/
‱ CSS Grid Layout‹
https://drafts.csswg.org/css-grid/
‱ Box Alignment‹
https://drafts.csswg.org/css-align/
The new CSS for Layout
Items in our layouts understand
themselves as part of a complete layout.
http://alistapart.com/article/fauxcolumns
http://colintoh.com/blog/display-table-anti-hero
Flexbox
Full height columns with
flexbox, taking advantage
of default alignment values.
.wrapper {
display: flex;
}
.sidebar {
flex: 1 1 30%;
}
.content {
flex: 1 1 70%;
}
Grid Layout
Full height columns in CSS
Grid Layout.
.wrapper {
display: grid;
grid-template-columns: 30% 70%;
}
.sidebar {
grid-column: 1;
}
.content {
grid-column: 2;
}
Separation of source and display
Flexbox
The flex-direction property
can take a value of row to
display things as a row or
column to display them as
a column.
nav ul{
display: flex;
justify-content: space-between;
flex-direction: row;
}
Flexbox
The visual order can be
switched using row-
reverse or column-reverse.
nav ul{
display: flex;
justify-content: space-between;
flex-direction: row-reverse;
}
Flexbox
Adding display: flex to our
container element causes
the items to display flexibly
in a row.
.wrapper {
display: flex;
}
Flexbox
The order property means
we can change the order of
flex items using CSS.
This does not change their
source order.
li:nth-child(1) {
order: 3;
}
li:nth-child(2) {
order: 1;
}
li:nth-child(3) {
order: 4;
}
li:nth-child(4) {
order: 2;
}
Grid Layout
I have created a grid on
my wrapper element.
The grid has 3 equal
width columns.
Rows will be created as
required as we position
items into them.
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
Grid Layout
I am positioning my
elements using CSS Grid
Layout line-based
positioning.
Setting a column and a
row line using the grid-
column and grid-row
properties.
li:nth-child(1) {
grid-column: 3 ;
grid-row: 2 ;
}
li:nth-child(2) {
grid-column: 1 ;
grid-row: 2 ;
}
li:nth-child(3) {
grid-column: 1 ;
grid-row: 1 ;
}
li:nth-child(4) {
grid-column: 2 ;
grid-row: 1 ;
}
CSSConf.asia - Laying out the future
CSS Grid automatic placement
https://drafts.csswg.org/css-grid/#grid-auto-flow-property
https://rachelandrew.co.uk/archives/2015/04/14/grid-layout-
automatic-placement-and-packing-modes/
Grid Layout
A list of colours.
<ul class="colors">
<li style="background-
color:#FFFFFF;color:black" class="white">FFF
FFF
</li>
<li style="background-
color:#CCCCCC;color:black">CCC CCC
</li>
<li style="background-
color:#999999;color:black" class="span3">999
999
</li>
</ul>
Grid Layout
Creating a flexible grid
with a flexible number of
columns.
.colors {
display: grid;
grid-template-columns:
repeat(auto-fill,minmax(80px, 1fr));
grid-gap: 2px;
grid-auto-rows: minmax(80px, auto);
}
CSSConf.asia - Laying out the future
Grid Layout
Positioning the white and
black blocks to stretch
across the grid.
Spanning tracks for some
other items.
.white {
grid-column: 1 / -1;
grid-row: 3;
}
.black {
grid-column: 1 / -1;
grid-row: 6;
}
.span2 {
grid-column-end: span 2;
grid-row-end: span 2;
}
.span3 {
grid-column-end: span 3;
grid-row-end: span 3;
}
.tall4 {
grid-row-end: span 4;
}
CSSConf.asia - Laying out the future
Grid Layout
Change the packing mode
to dense.
.colors {
display: grid;
grid-template-columns:
repeat(auto-fill,minmax(80px, 1fr));
grid-gap: 2px;
grid-auto-rows: minmax(80px, auto);
grid-auto-flow: dense;
}
CSSConf.asia - Laying out the future
With great power comes
responsibility.
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://drafts.csswg.org/css-flexbox/#order-accessibility
Authors must use order only for visual,
not logical, reordering of content. Style
sheets that use order to perform
logical reordering are non-conforming.
Léonie Watson | On CSS accessibility
and drinking tea | CSS Day 2016
https://vimeo.com/180566024
Control of alignment
CSS Box Alignment Module Level 3
“This module contains the features of CSS relating to the
alignment of boxes within their containers in the various CSS box
layout models: block layout, table layout, flex layout, and grid
layout.” - https://drafts.csswg.org/css-align/
It’s 2016. We can now centre things.
Box Alignment Properties
justify-content
align-content
justify-self
align-self
justify-items
align-items
Flexbox
The justify-content
property is set to space-
between.
The items at each end are
placed against the
container and the
remaining space
distributed evenly.
nav ul{
display: flex;
justify-content: space-between;
flex-direction: row;
}
Grid
If there is space in the grid
container after all column
and row tracks have been
added.
Use space-around and
space-between to space
the tracks.
.wrapper {
width: 500px;
height: 400px;
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(4, 80px);
grid-template-rows: repeat(3,100px);
align-content: space-around;
justify-content: space-between;
}
I can create this same
layout with flexbox or Grid.
With flexbox the items are
laid out in a row.
.wrapper {
display: flex;
}
.wrapper li {
flex: 1 0 25%;
}
The first item is at the
default stretch and as the
tallest item is dictating the
height of the flex container.
The second is entered in
the container.
The third aligned to the
start.
The fourth aligned to the
end.
.wrapper li:nth-child(2) {
align-self: center;
}
.wrapper li:nth-child(3) {
align-self: flex-start;
}
.wrapper li:nth-child(4) {
align-self: flex-end;
}
For Grid I use a single row,
4 column Grid.
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
Grid alignment properties
for the three landscape
images.
.wrapper li:nth-child(2) {
align-self: center;
}
.wrapper li:nth-child(3) {
align-self: start;
}
.wrapper li:nth-child(4) {
align-self: end;
}
Responsive by default
Ethan Marcotte, Fluid Grids
“
 every aspect of the grid—and the
elements laid upon it—can be
expressed as a proportion relative to
its container.”
target Ă· context = result
h1 {
margin-left: 14.575%; /* 144px / 988px = 0.14575 */
width: 70.85%; /* 700px / 988px = 0.7085 */
}
Flexbox
The most simple flexbox
example demonstrates
the inherent flexibility.
The items will be
displayed as a row, with
equal space between each
item.
nav ul{
display: flex;
justify-content: space-between;
}
The flex property
‱ flex-grow - add space
‱ flex-shrink - remove space
‱ flex-basis - the initial size before any growing or shrinking
Flexbox
flex: 1 1 300px;
flex-grow: 1
flex-shrink: 1;
flex-basis: 300px;
The initial width of our li
is 300 pixels, however it
can grow larger and
shrink smaller than 300
pixels.
.wrapper {
display: flex;
}
.wrapper li {
flex: 1 1 300px;
min-width: 1px;
}
CSSConf.asia - Laying out the future
Flexbox
flex: 1 1 300px;
flex-grow: 1
flex-shrink: 1;
flex-basis: 300px;
If we allow the flex items
to wrap we can see how
flex-basis works by
dragging the window
smaller.
.wrapper {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
.wrapper li {
flex: 1 1 300px;
min-width: 1px;
}
CSSConf.asia - Laying out the future
Flexbox
flex: 1 1 300px;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 300px;
The 3rd item has
flex: 0 1 300px;
so cannot grow.
.wrapper {
display: flex;
}
.wrapper li {
flex: 1 1 300px;
min-width: 1px;
}
.wrapper li:nth-child(3) {
flex: 0 1 300px;
}
CSSConf.asia - Laying out the future
Flexbox
If we set the 3rd item to‹
flex-grow: 2
This item will be assigned
twice of much of the
available free space after
we have reached the 300
pixel initial width.
.wrapper {
display: flex;
}
.wrapper li {
flex: 1 1 300px;
min-width: 1px;
}
.wrapper li:nth-child(3) {
flex: 2 1 300px;
}
CSSConf.asia - Laying out the future
http://madebymike.com.au/demos/flexbox-tester/
The CSS Grid Layout fr unit
Grid Layout
I am creating three grid
column tracks, all 1fr in
width.
This gives me three equally
sized column tracks.
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
Grid Layout
If I create the first column
as 600 pixels and then
have two 1fr columns the
600 pixel track is removed
from the available space
and the remainder is
distributed equally
between the two columns.
.wrapper {
display: grid;
grid-template-columns: 600px 1fr 1fr;
}
Grid Layout
With a 600 pixel column, a
1fr and a 3fr column. The
600 pixels is removed from
the available space then
the remaining space is
divided by 4.
The 1fr column gets 25%
and the 3fr column 75%.
.wrapper {
display: grid;
grid-template-columns: 600px 1fr 3fr;
}
CSSConf.asia - Laying out the future
Flexbox for 1 dimensional layout.
CSS Grid is for 2 dimensional layout.
CSSConf.asia - Laying out the future
The value of the grid-
template-columns
property says:
repeat this track listing,
auto-filing as many
columns with a minimum
width of 300 pixels and a
maximum of 1fr.
.wrapper {
display: grid;
grid-template-columns: repeat(auto-
fill, minmax(300px, 1fr));
}
CSSConf.asia - Laying out the future
Bringing it all together
CSSConf.asia - Laying out the future
CSSConf.asia - Laying out the future
CSSConf.asia - Laying out the future
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;
}
CSSConf.asia - Laying out the future
http://codepen.io/collection/DVKrKJ/
http://gridbyexample.com
http://caniuse.com/#feat=css-grid
http://caniuse.com/#feat=css-grid
http://gridbyexample.com/browsers
Feature Queries - your new best
friend
Feature Queries
Test for support of
property: value pairs.
@supports (display: grid) {
.has-grid {
/* CSS for grid browsers here */
}
}
Using 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/
Grid tips for Feature Queries
‱ Floated items that become grid or flex items lose their float
behaviour
‱ vertical-align has no effect on a grid item
‱ Items set to display: inline-block or block become grid items
‱ Your overrides mostly change widths, margins and padding.
‱ If grid tracks or flex-basis seem to be using a size you didn’t
expect, check your item widths!
http://codepen.io/rachelandrew/pen/WGNrPW
http://caniuse.com/#feat=css-featurequeries
Anything new in CSS you can use
feature queries to detect support.
Thank you
Slides & Resources: ‹
https://rachelandrew.co.uk/speaking/event/cssconf-asia-2016
http://csslayout.news - sign up for my weekly CSS Layout email
—
@rachelandrew | me@rachelandrew.co.uk
—
https://rachelandrew.co.uk | https://grabaperch.com

More Related Content

What's hot (20)

PDF
Next-level CSS
Rachel Andrew
 
PDF
Frontend United: Start using CSS Grid Layout today!
Rachel Andrew
 
PDF
Introducing CSS Grid Layout
Rachel Andrew
 
PDF
New CSS Meets the Real World
Rachel Andrew
 
PDF
Making the most of New CSS Layout
Rachel Andrew
 
PDF
Laracon Online: Grid and Flexbox
Rachel Andrew
 
PDF
CSS Grid Layout
Rachel Andrew
 
PDF
Confoo: The New CSS Layout
Rachel Andrew
 
PDF
The Right Layout Tool for the Job
Rachel Andrew
 
PDF
CSS Grid Layout - An Event Apart Orlando
Rachel Andrew
 
PDF
CSS Day: CSS Grid Layout
Rachel Andrew
 
PDF
An Event Apart Seattle - New CSS Layout Meets the Real World
Rachel Andrew
 
PDF
GOTO Berlin - You can use CSS for that
Rachel Andrew
 
PDF
An Event Apart Nashville: CSS Grid Layout
Rachel Andrew
 
PDF
Introduction to CSS Grid Layout
Rachel Andrew
 
PDF
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
Igalia
 
PDF
What I discovered about layout vis CSS Grid
Rachel Andrew
 
PDF
Flexbox and Grid Layout
Rachel Andrew
 
PDF
The New CSS Layout - dotCSS
Rachel Andrew
 
PDF
Future Layout & Performance
Rachel Andrew
 
Next-level CSS
Rachel Andrew
 
Frontend United: Start using CSS Grid Layout today!
Rachel Andrew
 
Introducing CSS Grid Layout
Rachel Andrew
 
New CSS Meets the Real World
Rachel Andrew
 
Making the most of New CSS Layout
Rachel Andrew
 
Laracon Online: Grid and Flexbox
Rachel Andrew
 
CSS Grid Layout
Rachel Andrew
 
Confoo: The New CSS Layout
Rachel Andrew
 
The Right Layout Tool for the Job
Rachel Andrew
 
CSS Grid Layout - An Event Apart Orlando
Rachel Andrew
 
CSS Day: CSS Grid Layout
Rachel Andrew
 
An Event Apart Seattle - New CSS Layout Meets the Real World
Rachel Andrew
 
GOTO Berlin - You can use CSS for that
Rachel Andrew
 
An Event Apart Nashville: CSS Grid Layout
Rachel Andrew
 
Introduction to CSS Grid Layout
Rachel Andrew
 
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
Igalia
 
What I discovered about layout vis CSS Grid
Rachel Andrew
 
Flexbox and Grid Layout
Rachel Andrew
 
The New CSS Layout - dotCSS
Rachel Andrew
 
Future Layout & Performance
Rachel Andrew
 

Viewers also liked (13)

PDF
Conference Speakers
Rachel Andrew
 
PDF
Contribution & Confidence, All Things Open Keynote
Rachel Andrew
 
PDF
Knowing it all
Rachel Andrew
 
PPT
Menoovr
menoovr
 
PDF
Hoppala at O'Reilly Where 2.0 Conference
Marc René Gardeya
 
PPTX
Open Standards in the Walled Garden
digitalbindery
 
PPT
Demand Media
Web 2.0 Expo
 
PPT
Kevin Kelly
Web 2.0 Expo
 
PDF
Confoo: You can use CSS for that!
Rachel Andrew
 
PDF
Driving the Future of Smart Cities - How to Beat the Traffic
VMware Tanzu
 
PDF
The Future of Frontend - what is new in CSS?
Rachel Andrew
 
KEY
Terry Jones TOC 2011 slides
Fluidinfo
 
PDF
Everything else
Rachel Andrew
 
Conference Speakers
Rachel Andrew
 
Contribution & Confidence, All Things Open Keynote
Rachel Andrew
 
Knowing it all
Rachel Andrew
 
Menoovr
menoovr
 
Hoppala at O'Reilly Where 2.0 Conference
Marc René Gardeya
 
Open Standards in the Walled Garden
digitalbindery
 
Demand Media
Web 2.0 Expo
 
Kevin Kelly
Web 2.0 Expo
 
Confoo: You can use CSS for that!
Rachel Andrew
 
Driving the Future of Smart Cities - How to Beat the Traffic
VMware Tanzu
 
The Future of Frontend - what is new in CSS?
Rachel Andrew
 
Terry Jones TOC 2011 slides
Fluidinfo
 
Everything else
Rachel Andrew
 
Ad

Similar to CSSConf.asia - Laying out the future (20)

PDF
CSS Conf Budapest - New CSS Layout
Rachel Andrew
 
PDF
Flexbox and Grid Layout
Rachel Andrew
 
PDF
But what about old browsers?
Rachel Andrew
 
PDF
Fluent: Making Sense of the New CSS Layout
Rachel Andrew
 
PDF
ConFoo 2016: Making Sense of CSS Layout
Rachel Andrew
 
PDF
View Source London: Solving Layout Problems with CSS Grid & Friends
Rachel Andrew
 
PDF
An Event Apart SF: CSS Grid Layout
Rachel Andrew
 
PDF
CSS Grid Layout for Topconf, Linz
Rachel Andrew
 
PDF
Solving Layout Problems with CSS Grid & Friends - DevFest17
Rachel Andrew
 
PDF
Start Using CSS Grid Layout Today - RuhrJS
Rachel Andrew
 
PDF
Devoxx Belgium: CSS Grid Layout
Rachel Andrew
 
PDF
CSS3 Layout
Zoe Gillenwater
 
PPTX
CSS Flexbox and Grid: The future of website layouts - DN Scrum Breakfast - Au...
Scrum Breakfast Vietnam
 
PDF
Evergreen websites for Evergreen browsers
Rachel Andrew
 
PDF
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Rachel Andrew
 
PPTX
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
ganeshchettipalli
 
PDF
The Future of CSS Layout
Zoe Gillenwater
 
PDF
Solving Layout Problems with CSS Grid & Friends - WEBU17
Rachel Andrew
 
PDF
Solving Layout Problems With CSS Grid and Friends
FITC
 
PDF
Solving Layout Problems with CSS Grid & Friends - NordicJS
Rachel Andrew
 
CSS Conf Budapest - New CSS Layout
Rachel Andrew
 
Flexbox and Grid Layout
Rachel Andrew
 
But what about old browsers?
Rachel Andrew
 
Fluent: Making Sense of the New CSS Layout
Rachel Andrew
 
ConFoo 2016: Making Sense of CSS Layout
Rachel Andrew
 
View Source London: Solving Layout Problems with CSS Grid & Friends
Rachel Andrew
 
An Event Apart SF: CSS Grid Layout
Rachel Andrew
 
CSS Grid Layout for Topconf, Linz
Rachel Andrew
 
Solving Layout Problems with CSS Grid & Friends - DevFest17
Rachel Andrew
 
Start Using CSS Grid Layout Today - RuhrJS
Rachel Andrew
 
Devoxx Belgium: CSS Grid Layout
Rachel Andrew
 
CSS3 Layout
Zoe Gillenwater
 
CSS Flexbox and Grid: The future of website layouts - DN Scrum Breakfast - Au...
Scrum Breakfast Vietnam
 
Evergreen websites for Evergreen browsers
Rachel Andrew
 
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Rachel Andrew
 
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
ganeshchettipalli
 
The Future of CSS Layout
Zoe Gillenwater
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Rachel Andrew
 
Solving Layout Problems With CSS Grid and Friends
FITC
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Rachel Andrew
 
Ad

More from Rachel Andrew (14)

PDF
All Day Hey! Unlocking The Power of CSS Grid Layout
Rachel Andrew
 
PDF
SmashingConf SF: Unlocking the Power of CSS Grid Layout
Rachel Andrew
 
PDF
Unlocking the Power of CSS Grid Layout
Rachel Andrew
 
PDF
The Creative New World of CSS
Rachel Andrew
 
PDF
Into the Weeds of CSS Layout
Rachel Andrew
 
PDF
Graduating to Grid
Rachel Andrew
 
PDF
DevFest Nantes - Start Using CSS Grid Layout today
Rachel Andrew
 
PDF
404.ie: Solving Layout Problems with CSS Grid & Friends
Rachel Andrew
 
PDF
Google Developers Experts Summit 2017 - CSS Layout
Rachel Andrew
 
PDF
Web Summer Camp Keynote
Rachel Andrew
 
PDF
New CSS Layout Meets the Real World
Rachel Andrew
 
PDF
An Event Apart DC - New CSS Layout meets the Real World
Rachel Andrew
 
PDF
Perch, Patterns and Old Browsers
Rachel Andrew
 
PDF
Where does CSS come from?
Rachel Andrew
 
All Day Hey! Unlocking The Power of CSS Grid Layout
Rachel Andrew
 
SmashingConf SF: Unlocking the Power of CSS Grid Layout
Rachel Andrew
 
Unlocking the Power of CSS Grid Layout
Rachel Andrew
 
The Creative New World of CSS
Rachel Andrew
 
Into the Weeds of CSS Layout
Rachel Andrew
 
Graduating to Grid
Rachel Andrew
 
DevFest Nantes - Start Using CSS Grid Layout today
Rachel Andrew
 
404.ie: Solving Layout Problems with CSS Grid & Friends
Rachel Andrew
 
Google Developers Experts Summit 2017 - CSS Layout
Rachel Andrew
 
Web Summer Camp Keynote
Rachel Andrew
 
New CSS Layout Meets the Real World
Rachel Andrew
 
An Event Apart DC - New CSS Layout meets the Real World
Rachel Andrew
 
Perch, Patterns and Old Browsers
Rachel Andrew
 
Where does CSS come from?
Rachel Andrew
 

Recently uploaded (20)

PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 

CSSConf.asia - Laying out the future

  • 1. Laying out the future. Rachel Andrew, ‹ CSSConf.asia 2016
  • 2. Rachel Andrew rachelandrew.co.uk @rachelandrew CSS Working Group Invited Expert Google Developer Expert for Web Technologies Co-founder Perch CMS: https://grabaperch.com Contact: me@rachelandrew.co.uk
  • 3. Modern CSS Layout? ‱ Floats ‱ Inline-block ‱ display: table ‱ Absolute & Relative positioning ‱ Frameworks 
 lots of frameworks
  • 4. Our great hopes for layout ‱ Flexbox‹ https://drafts.csswg.org/css-flexbox/ ‱ CSS Grid Layout‹ https://drafts.csswg.org/css-grid/ ‱ Box Alignment‹ https://drafts.csswg.org/css-align/
  • 5. The new CSS for Layout
  • 6. Items in our layouts understand themselves as part of a complete layout.
  • 9. Flexbox Full height columns with flexbox, taking advantage of default alignment values. .wrapper { display: flex; } .sidebar { flex: 1 1 30%; } .content { flex: 1 1 70%; }
  • 10. Grid Layout Full height columns in CSS Grid Layout. .wrapper { display: grid; grid-template-columns: 30% 70%; } .sidebar { grid-column: 1; } .content { grid-column: 2; }
  • 11. Separation of source and display
  • 12. Flexbox The flex-direction property can take a value of row to display things as a row or column to display them as a column. nav ul{ display: flex; justify-content: space-between; flex-direction: row; }
  • 13. Flexbox The visual order can be switched using row- reverse or column-reverse. nav ul{ display: flex; justify-content: space-between; flex-direction: row-reverse; }
  • 14. Flexbox Adding display: flex to our container element causes the items to display flexibly in a row. .wrapper { display: flex; }
  • 15. Flexbox The order property means we can change the order of flex items using CSS. This does not change their source order. li:nth-child(1) { order: 3; } li:nth-child(2) { order: 1; } li:nth-child(3) { order: 4; } li:nth-child(4) { order: 2; }
  • 16. Grid Layout I have created a grid on my wrapper element. The grid has 3 equal width columns. Rows will be created as required as we position items into them. .wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr; }
  • 17. Grid Layout I am positioning my elements using CSS Grid Layout line-based positioning. Setting a column and a row line using the grid- column and grid-row properties. li:nth-child(1) { grid-column: 3 ; grid-row: 2 ; } li:nth-child(2) { grid-column: 1 ; grid-row: 2 ; } li:nth-child(3) { grid-column: 1 ; grid-row: 1 ; } li:nth-child(4) { grid-column: 2 ; grid-row: 1 ; }
  • 19. CSS Grid automatic placement https://drafts.csswg.org/css-grid/#grid-auto-flow-property https://rachelandrew.co.uk/archives/2015/04/14/grid-layout- automatic-placement-and-packing-modes/
  • 20. Grid Layout A list of colours. <ul class="colors"> <li style="background- color:#FFFFFF;color:black" class="white">FFF FFF </li> <li style="background- color:#CCCCCC;color:black">CCC CCC </li> <li style="background- color:#999999;color:black" class="span3">999 999 </li> </ul>
  • 21. Grid Layout Creating a flexible grid with a flexible number of columns. .colors { display: grid; grid-template-columns: repeat(auto-fill,minmax(80px, 1fr)); grid-gap: 2px; grid-auto-rows: minmax(80px, auto); }
  • 23. Grid Layout Positioning the white and black blocks to stretch across the grid. Spanning tracks for some other items. .white { grid-column: 1 / -1; grid-row: 3; } .black { grid-column: 1 / -1; grid-row: 6; } .span2 { grid-column-end: span 2; grid-row-end: span 2; } .span3 { grid-column-end: span 3; grid-row-end: span 3; } .tall4 { grid-row-end: span 4; }
  • 25. Grid Layout Change the packing mode to dense. .colors { display: grid; grid-template-columns: repeat(auto-fill,minmax(80px, 1fr)); grid-gap: 2px; grid-auto-rows: minmax(80px, auto); grid-auto-flow: dense; }
  • 27. With great power comes responsibility.
  • 28. 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.
  • 29. https://drafts.csswg.org/css-flexbox/#order-accessibility Authors must use order only for visual, not logical, reordering of content. Style sheets that use order to perform logical reordering are non-conforming.
  • 30. LĂ©onie Watson | On CSS accessibility and drinking tea | CSS Day 2016 https://vimeo.com/180566024
  • 32. CSS Box Alignment Module Level 3 “This module contains the features of CSS relating to the alignment of boxes within their containers in the various CSS box layout models: block layout, table layout, flex layout, and grid layout.” - https://drafts.csswg.org/css-align/
  • 33. It’s 2016. We can now centre things.
  • 35. Flexbox The justify-content property is set to space- between. The items at each end are placed against the container and the remaining space distributed evenly. nav ul{ display: flex; justify-content: space-between; flex-direction: row; }
  • 36. Grid If there is space in the grid container after all column and row tracks have been added. Use space-around and space-between to space the tracks. .wrapper { width: 500px; height: 400px; display: grid; grid-gap: 10px; grid-template-columns: repeat(4, 80px); grid-template-rows: repeat(3,100px); align-content: space-around; justify-content: space-between; }
  • 37. I can create this same layout with flexbox or Grid. With flexbox the items are laid out in a row. .wrapper { display: flex; } .wrapper li { flex: 1 0 25%; }
  • 38. The first item is at the default stretch and as the tallest item is dictating the height of the flex container. The second is entered in the container. The third aligned to the start. The fourth aligned to the end. .wrapper li:nth-child(2) { align-self: center; } .wrapper li:nth-child(3) { align-self: flex-start; } .wrapper li:nth-child(4) { align-self: flex-end; }
  • 39. For Grid I use a single row, 4 column Grid. .wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; }
  • 40. Grid alignment properties for the three landscape images. .wrapper li:nth-child(2) { align-self: center; } .wrapper li:nth-child(3) { align-self: start; } .wrapper li:nth-child(4) { align-self: end; }
  • 42. Ethan Marcotte, Fluid Grids “
 every aspect of the grid—and the elements laid upon it—can be expressed as a proportion relative to its container.”
  • 43. target Ă· context = result h1 { margin-left: 14.575%; /* 144px / 988px = 0.14575 */ width: 70.85%; /* 700px / 988px = 0.7085 */ }
  • 44. Flexbox The most simple flexbox example demonstrates the inherent flexibility. The items will be displayed as a row, with equal space between each item. nav ul{ display: flex; justify-content: space-between; }
  • 45. The flex property ‱ flex-grow - add space ‱ flex-shrink - remove space ‱ flex-basis - the initial size before any growing or shrinking
  • 46. Flexbox flex: 1 1 300px; flex-grow: 1 flex-shrink: 1; flex-basis: 300px; The initial width of our li is 300 pixels, however it can grow larger and shrink smaller than 300 pixels. .wrapper { display: flex; } .wrapper li { flex: 1 1 300px; min-width: 1px; }
  • 48. Flexbox flex: 1 1 300px; flex-grow: 1 flex-shrink: 1; flex-basis: 300px; If we allow the flex items to wrap we can see how flex-basis works by dragging the window smaller. .wrapper { display: flex; flex-flow: row wrap; justify-content: space-around; } .wrapper li { flex: 1 1 300px; min-width: 1px; }
  • 50. Flexbox flex: 1 1 300px; flex-grow: 1; flex-shrink: 1; flex-basis: 300px; The 3rd item has flex: 0 1 300px; so cannot grow. .wrapper { display: flex; } .wrapper li { flex: 1 1 300px; min-width: 1px; } .wrapper li:nth-child(3) { flex: 0 1 300px; }
  • 52. Flexbox If we set the 3rd item to‹ flex-grow: 2 This item will be assigned twice of much of the available free space after we have reached the 300 pixel initial width. .wrapper { display: flex; } .wrapper li { flex: 1 1 300px; min-width: 1px; } .wrapper li:nth-child(3) { flex: 2 1 300px; }
  • 55. The CSS Grid Layout fr unit
  • 56. Grid Layout I am creating three grid column tracks, all 1fr in width. This gives me three equally sized column tracks. .wrapper { display: grid; grid-template-columns: 1fr 1fr 1fr; }
  • 57. Grid Layout If I create the first column as 600 pixels and then have two 1fr columns the 600 pixel track is removed from the available space and the remainder is distributed equally between the two columns. .wrapper { display: grid; grid-template-columns: 600px 1fr 1fr; }
  • 58. Grid Layout With a 600 pixel column, a 1fr and a 3fr column. The 600 pixels is removed from the available space then the remaining space is divided by 4. The 1fr column gets 25% and the 3fr column 75%. .wrapper { display: grid; grid-template-columns: 600px 1fr 3fr; }
  • 60. Flexbox for 1 dimensional layout. CSS Grid is for 2 dimensional layout.
  • 62. The value of the grid- template-columns property says: repeat this track listing, auto-filing as many columns with a minimum width of 300 pixels and a maximum of 1fr. .wrapper { display: grid; grid-template-columns: repeat(auto- fill, minmax(300px, 1fr)); }
  • 64. Bringing it all together
  • 68. Using the minmax() function with grid-auto- rows. .home-hero { display: grid; grid-gap: 1px; grid-auto-rows: minmax(150px, auto); }
  • 69. 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; }
  • 76. Feature Queries - your new best friend
  • 77. Feature Queries Test for support of property: value pairs. @supports (display: grid) { .has-grid { /* CSS for grid browsers here */ } }
  • 78. Using 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/
  • 79. Grid tips for Feature Queries ‱ Floated items that become grid or flex items lose their float behaviour ‱ vertical-align has no effect on a grid item ‱ Items set to display: inline-block or block become grid items ‱ Your overrides mostly change widths, margins and padding. ‱ If grid tracks or flex-basis seem to be using a size you didn’t expect, check your item widths!
  • 82. Anything new in CSS you can use feature queries to detect support.
  • 83. Thank you Slides & Resources: ‹ https://rachelandrew.co.uk/speaking/event/cssconf-asia-2016 http://csslayout.news - sign up for my weekly CSS Layout email — @rachelandrew | me@rachelandrew.co.uk — https://rachelandrew.co.uk | https://grabaperch.com