SlideShare a Scribd company logo
1 of 74
Download to read offline
S T E P H E N H AY
BDCONF, NASHVILLE 2013

Flexbox
O N E G I A N T L E A P F O R W E B L AY O U T
The design-in-the-browser hamburger
The design-in-the-browser hamburger
DESIGNER
The design-in-the-browser hamburger
DESIGNER

CODE
(the stuff that’s really happening)
The design-in-the-browser hamburger
DESIGNER

MAGIC

CODE
(the stuff that’s really happening)
The design-in-the-browser hamburger
DESIGNER

MAGIC

CODE
(the stuff that’s really happening)
The design-in-the-browser hamburger
DESIGNER

MAGIC

CODE
(the stuff that’s really happening)
The design-in-the-browser hamburger

DESIGNER
MAGIC
CODE
Designers aren’t stupid.
Designers aren’t stupid.
Many designers are willing to explore web tech as a
design tool, but we have to make the right things easier.
Flexbox is a step in the right direction.
image: NASA
~8 years
image: NASA
https://en.wikipedia.org/wiki/File:First_Web_Server.jpg

~1 year
CASCADING STYLE SHEETS, LEVEL 1

~2 years
CSS has been around for

17 years
and we finally have “real” layout
in the form of Flexible Box Layout Module

aka “Flexbox”
“Layout is hard.”
image: NASA
“Layout solutions are an
interesting area in CSS to me.”
– Tab Atkins
We’re talking about this version
http://dev.w3.org/csswg/css-flexbox/
Two major types of “real” web layout
Two major types of “real” web layout
Flexbox helps us deal with

Available

space
even when we don’t know what that will be
alignment

both horizontally and vertically

Flexbox helps us with
Flexbox helps us with

ordre
display
A quick introduction to Flexbox
Terminology
Axes & Size
Flex
Alignment
Order
Leave your layout baggage
at the door.
Terminology
Flex containers
Flex items
Main axis / size / dimension
Cross axis / size / dimension
Start / end
CODE
http://www.flickr.com/photos/evdaimon/337754011/
display: flex | inline-flex
Hi, Bob.
(Bob is a flex container)

#bob { display: flex; }
display: flex | inline-flex
Flex items
Items in a flex container are, by default, flex items
(even anonymous block boxes)

I’m a flex item!

Me too!

Me three!
Direction
#bob {
flex-direction: row | row-reverse |
column | column-reverse;
flex-wrap: no-wrap | wrap | wrap-reverse;
}
SHORTHAND:

#bob { flex-flow: row wrap; }
Main axis
+ main size, main dimension

in the case of flex-direction: row
Cross axis
+ cross size, cross dimension

in the case of flex-direction: row
Start & End
depends on direction
C R O S S S TA R T

M A I N S TA R T

CENTER

MAIN END

CROSS END
in the case of flex-direction: row
Start & End
depends on direction
M A I N S TA R T

C R O S S S TA R T

CENTER

CROSS END

MAIN END
in the case of flex-direction: column
Flex
.flex-item {
flex: flex-grow flex-shrink flex-basis;
}

EXAMPLE:

.foo { flex: 0 1 150px; }
Flex
.flex-item {
flex: flex-grow flex-shrink flex-basis;
}

EXAMPLE:

.foo { flex: 0 1 150px; }
Flex common values (1)
.foo { flex: initial; }
I S E Q U I VA L E N T T O :

.foo { flex: 0 1 auto;}

width:
150px

width:
150px

width:
150px
Flex common values (2)
.foo { flex: auto; }
I S E Q U I VA L E N T T O :

.foo { flex: 1 1 auto;}

width:
150px

width:
150px

width:
150px
Flex common values (3)
.foo { flex: none; }
I S E Q U I VA L E N T T O :

.foo { flex: 0 0 auto;}

width:
150px

width:
150px

width:
150px
Flex common values (4)
.foo { flex: [n]; }
I S E Q U I VA L E N T T O :

.foo { flex: [n] 1 0%;}

flex: 1

flex: 1

flex: 1
Flex flex: [n]

flex: 1

flex: 1

flex: 2
Flex flex: [n]

flex: 1

flex: 5

flex: 2
Alignment
auto-margins

.foo { margin-top: auto; }

no margin
margin-top: auto

no margin
Alignment
along the main axis: justify-content
(align-content for multiple lines along cross axis)

#bob { justify-content: flex-start |
flex-end | center | space-between |
space-around }
JUSTIFY-CONTENT

in the case of flex-direction: row
http://dev.w3.org/csswg/css-flexbox/
http://dev.w3.org/csswg/css-flexbox/
Alignment
along the cross axis: align-items
(align-self can be applied to the flex items themselves/individually)

#bob { align-items: flex-start |
flex-end | center | baseline | stretch }

ALIGN-ITEMS

in the case of flex-direction: row
http://dev.w3.org/csswg/css-flexbox/
Order
changes the visual order vs. the source order

.foo { order: [n]; }

.item:nth-child(3) { order: -1; }

3

1

2
Common use cases
True centering (both axes)
Multi-box layouts (products, teasers)
Unknown menu items
Display order
Wrapping (menu items, boxes)
Tab groups
Form layout
A small example
Structured content
Basic styles
display:flex on container
flex-direction:column
margin-auto
on icons and
form
flex:1
on input field
order
for avatar display
done.
Browser compatibility
source: http://beta.caniuse.com/#search=flexbox
Don’t sweat the prefixes
http://leaverou.github.io/prefixfree/
meh. (but go ahead if you really want to)

source: http://coding.smashingmagazine.com/2013/05/22/centering-elements-with-flexbox/
Syntax variations
http://coding.smashingmagazine.com/2013/05/22/centering-elements-with-flexbox/
Before you get all excited…
Flexboxes aren’t ideal for page layout
http://www.xanthir.com/blog/b4580
Flexbox is ideal for components

http://pattern-lab.info/
Flexbox is ideal for components

http://pattern-lab.info/
The hardest thing to learn about new tools
is not how to use them, but when to use them.
have fun
keep learning
THANK YOU!
@stephenhay

More Related Content

What's hot

What's hot (11)

Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)
 
Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)
 
Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)
 
The Power of CSS Flexbox
The Power of CSS FlexboxThe Power of CSS Flexbox
The Power of CSS Flexbox
 
Flexbox and Grid Layout: How you will structure layouts tomorrow.
Flexbox and Grid Layout: How you will structure layouts tomorrow.Flexbox and Grid Layout: How you will structure layouts tomorrow.
Flexbox and Grid Layout: How you will structure layouts tomorrow.
 
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
Flexbox: One Giant Leap for Web Layout (GenerateConf 2013)
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)
 
Ridiculously Easy Layouts with Flexbox
Ridiculously Easy Layouts with FlexboxRidiculously Easy Layouts with Flexbox
Ridiculously Easy Layouts with Flexbox
 
Flexbox every developers dream
Flexbox every developers dreamFlexbox every developers dream
Flexbox every developers dream
 
Fewd week3 slides
Fewd week3 slidesFewd week3 slides
Fewd week3 slides
 
Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!
 

Similar to Flexbox: One Giant Leap for Web Layout (Breaking Development 2013)

CSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignCSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive Design
Arash Milani
 

Similar to Flexbox: One Giant Leap for Web Layout (Breaking Development 2013) (20)

Understanding flex box CSS Day 2016
Understanding flex box CSS Day 2016Understanding flex box CSS Day 2016
Understanding flex box CSS Day 2016
 
Layout with flexbox
Layout with flexboxLayout with flexbox
Layout with flexbox
 
Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?
 
CSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignCSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive Design
 
Building Layouts with CSS
Building Layouts with CSSBuilding Layouts with CSS
Building Layouts with CSS
 
Making CSS and Firebug Your New Friends
Making CSS and Firebug Your New FriendsMaking CSS and Firebug Your New Friends
Making CSS and Firebug Your New Friends
 
A complete guide to flexbox
A complete guide to flexboxA complete guide to flexbox
A complete guide to flexbox
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into Practice
 
CSS flexbox
CSS flexboxCSS flexbox
CSS flexbox
 
CSS Conf Budapest - New CSS Layout
CSS Conf Budapest - New CSS LayoutCSS Conf Budapest - New CSS Layout
CSS Conf Budapest - New CSS Layout
 
Introduction to flexbox
Introduction  to  flexboxIntroduction  to  flexbox
Introduction to flexbox
 
"CSS you've never known" by Bohdan Rusinka
"CSS you've never known" by Bohdan Rusinka "CSS you've never known" by Bohdan Rusinka
"CSS you've never known" by Bohdan Rusinka
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexbox
 
But what about old browsers?
But what about old browsers?But what about old browsers?
But what about old browsers?
 
The New CSS Layout - dotCSS
The New CSS Layout - dotCSSThe New CSS Layout - dotCSS
The New CSS Layout - dotCSS
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
 
Flexing Your WordPress Themes
Flexing Your WordPress ThemesFlexing Your WordPress Themes
Flexing Your WordPress Themes
 
css flex box
css flex boxcss flex box
css flex box
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Future Layout & Performance
Future Layout & PerformanceFuture Layout & Performance
Future Layout & Performance
 

More from Stephen Hay

Fronteers Workshop: Rabid Prototyping
Fronteers Workshop: Rabid PrototypingFronteers Workshop: Rabid Prototyping
Fronteers Workshop: Rabid Prototyping
Stephen Hay
 
Meta layout: a closer look at media queries
Meta layout: a closer look at media queriesMeta layout: a closer look at media queries
Meta layout: a closer look at media queries
Stephen Hay
 
HTML5 & Webrichtlijnen 2
HTML5 & Webrichtlijnen 2HTML5 & Webrichtlijnen 2
HTML5 & Webrichtlijnen 2
Stephen Hay
 

More from Stephen Hay (20)

From Deception to Clarity
From Deception to ClarityFrom Deception to Clarity
From Deception to Clarity
 
The Backside of the Class (CSS Day 2015)
The Backside of the Class (CSS Day 2015)The Backside of the Class (CSS Day 2015)
The Backside of the Class (CSS Day 2015)
 
The Art of Deception
The Art of DeceptionThe Art of Deception
The Art of Deception
 
Sculpting Text: Easing the Pain of Designing in the Browser
Sculpting Text: Easing the Pain of Designing in the BrowserSculpting Text: Easing the Pain of Designing in the Browser
Sculpting Text: Easing the Pain of Designing in the Browser
 
Power Tools For Browser-Based Design
Power Tools For Browser-Based DesignPower Tools For Browser-Based Design
Power Tools For Browser-Based Design
 
UIE Virtual Seminar: Responsive Web Design Workflow
UIE Virtual Seminar: Responsive Web Design WorkflowUIE Virtual Seminar: Responsive Web Design Workflow
UIE Virtual Seminar: Responsive Web Design Workflow
 
The New Photoshop, Part 2: The Revenge of the Web (FEC13)
The New Photoshop, Part 2: The Revenge of the Web (FEC13)The New Photoshop, Part 2: The Revenge of the Web (FEC13)
The New Photoshop, Part 2: The Revenge of the Web (FEC13)
 
Flexbox: One Giant Leap for Web Layout (CSS Day 2013)
Flexbox: One Giant Leap for Web Layout (CSS Day 2013)Flexbox: One Giant Leap for Web Layout (CSS Day 2013)
Flexbox: One Giant Leap for Web Layout (CSS Day 2013)
 
The New Photoshop, Part 2: The Revenge of the Web
The New Photoshop, Part 2: The Revenge of the WebThe New Photoshop, Part 2: The Revenge of the Web
The New Photoshop, Part 2: The Revenge of the Web
 
Style Guides Are The New Photoshop (Smashing Conference 2012)
Style Guides Are The New Photoshop (Smashing Conference 2012)Style Guides Are The New Photoshop (Smashing Conference 2012)
Style Guides Are The New Photoshop (Smashing Conference 2012)
 
Style Guides Are The New Photoshop (Fronteers 2012)
Style Guides Are The New Photoshop (Fronteers 2012)Style Guides Are The New Photoshop (Fronteers 2012)
Style Guides Are The New Photoshop (Fronteers 2012)
 
Responsive Design Workflow: Webshaped 2012
Responsive Design Workflow: Webshaped 2012Responsive Design Workflow: Webshaped 2012
Responsive Design Workflow: Webshaped 2012
 
Responsive Design Workflow: Mobilism 2012
Responsive Design Workflow: Mobilism 2012Responsive Design Workflow: Mobilism 2012
Responsive Design Workflow: Mobilism 2012
 
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
 
Go With The Flow
Go With The FlowGo With The Flow
Go With The Flow
 
Fronteers Workshop: Rabid Prototyping
Fronteers Workshop: Rabid PrototypingFronteers Workshop: Rabid Prototyping
Fronteers Workshop: Rabid Prototyping
 
Meta layout: a closer look at media queries
Meta layout: a closer look at media queriesMeta layout: a closer look at media queries
Meta layout: a closer look at media queries
 
Real-world Responsive Design @ Breaking Development 2011
Real-world Responsive Design @ Breaking Development 2011Real-world Responsive Design @ Breaking Development 2011
Real-world Responsive Design @ Breaking Development 2011
 
HTML5 & Webrichtlijnen 2
HTML5 & Webrichtlijnen 2HTML5 & Webrichtlijnen 2
HTML5 & Webrichtlijnen 2
 
Real-world Responsive Design
Real-world Responsive DesignReal-world Responsive Design
Real-world Responsive Design
 

Recently uploaded

Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Recently uploaded (20)

ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 

Flexbox: One Giant Leap for Web Layout (Breaking Development 2013)