SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
IS FLEXBOX
THE FUTURE OF LAYOUT?
IS FLEXBOX
THE FUTURE OF LAYOUT?
IS FLEXBOX
THE FUTURE OF LAYOUT?
james williamson | lynda.com
Monday, July 22, 2013
Hello.
I’m JamesWilliamson
happy to be here
@jameswillweb on the Twitter
| senior author
Monday, July 22, 2013
What are we going
to talk about?
Flexbox... and can it fix what’s
wrong with CSS layout?
Monday, July 22, 2013
Be honest. How many techniques can you
think of, just off the top of your head, for
vertically centering something?
How easy are they?
I rest my case.
CSS layout should be easier
Monday, July 22, 2013
Which brings us to Flexbox
Flexbox allows us to control the
size, order, and alignment of
elements along multiple axes.
Monday, July 22, 2013
Why is it awesome?
Some of the high points:
It’s flexible!
I mean, look at the name.You can easily make things stretch
and flex to fit available space, great for responsive design.
Easy alignment
Horizontal, vertical, baseline... it’s all good.
Source order independence
You want that before this, but only when that? OK.
Easy Syntax
You can learn it in one afternoon.
Monday, July 22, 2013
pre 2008
CSS Working Group discusses proposing a
Flexible Box Model similar to what is found in
XUL and XAML.
2008 2009 2010 2011 2012
Before you use Flexbox, you need to
know a little history
Monday, July 22, 2013
2009
The Flexible Box Layout Module is published as a working
draft. Chrome and Safari add partial support while Mozilla
support relies on older XUL implementation.The syntax
closely follows XUL flexbox syntax and is often referred to
as “Flexbox 2009.”
2008 2009 2010 2011 2012
Before you use Flexbox, you need to
know a little history
Monday, July 22, 2013
2011
Tab Atkins takes over as editor for the Flexbox Spec and
publishes two working drafts over the course of the
year.These drafts re-write the syntax significantly and
are sometimes referred to as “tweener” syntax. Chrome,
Opera and & IE 10 begin to implement this syntax.
2008 2009 2010 2011 2012
Before you use Flexbox, you need to
know a little history
Monday, July 22, 2013
2012
Syntax is further changed and refined. Spec is now a
Candidate Recommendation. Opera releases
un-prefixed support, Chrome supports the current
syntax in prefixed form, and IE 10 adds prefixed
support for the “tweener” syntax. Mozilla is close to
releasing unprefixed support.
2008 2009 2010 2011 2012
Before you use Flexbox, you need to
know a little history
Monday, July 22, 2013
Why does this matter?
In order to use Flexbox effectively, you’ll need
to know who supports the 2009 syntax, the
“tweener” syntax, the modern syntax, and
when to use vendor prefixes.
Monday, July 22, 2013
So... how’s support?
Browser
Firefox	
  (older)
Firefox
Google	
  Chrome
Safari
Opera
Internet	
  Explorer
iOS	
  Safari
Opera	
  Mini
Opera	
  Mobile
Android	
  Browser
Chrome	
  for	
  Android
Blackberry	
  Browser
support
2.0+
22+
22+
5.1+
12.1+
10+
3.2
5	
  -­‐	
  7
12.0+
2.1
27
10+
notes
old	
  XUL	
  syntax
with	
  -­‐webkit-­‐	
  prefix
-­‐ms-­‐	
  prefix,	
  uses	
  tweener	
  syntax
2009	
  syntax
2009	
  syntax,	
  -­‐webkit-­‐	
  prefix
with	
  -­‐webkit-­‐	
  prefix
Wait....	
  what?
2012	
  syntax	
  supported	
  	
  	
  	
  	
  	
  	
  	
  2009	
  syntax	
  	
  	
  	
  	
  	
  	
  	
  nada
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (as	
  of	
  07-­‐22-­‐13)
Monday, July 22, 2013
How does Flexbox work?
Basic concepts:
It’s a new layout mode
Joins block, inline, table, and positioned
Similar to block layout
Containing elements are laid out in a flow direction
Has super powers
Flow direction can be up or down, left or right, display
order can be reversed, elements can “flex” their size to
respond to available space and align to their containers
or other elements
Monday, July 22, 2013
How does Flexbox work?
Basic steps:
Define flex containers
All direct child elements become flex items
Establish flow direction
Flex containers can flow either in a row or column and can
be single or multiline
Go crazy with the cheese whiz
Flex items can now be spaced, flexed, aligned, or
arranged as you see fit within the flow direction
Monday, July 22, 2013
How does Flexbox work?
It’s all about the axis... er axes.
flex itemflex item
flex container
main axis
cross axis
Monday, July 22, 2013
Flexbox syntax*
Defining flex containers
.flex	
  {
	
   display:	
  -­‐webkit-­‐flex;
	
   display:	
  -­‐ms-­‐flexbox;
	
   display:	
  flex;
}
*A note about syntax.I’ll be showing 2012 syntax including webkit
prefixes,IE prefix (“tweener” syntax),and unprefixed syntax.I won’t show
older (2009 syntax) or older -o- and -moz- prefixes
(there’s also an inline-flex variation)
Monday, July 22, 2013
Flexbox syntax
Setting flow direction and line wrap
.flex	
  {
	
   -­‐webkit-­‐flex-­‐flow:	
  <flex	
  direction>	
  |	
  <flex	
  wrap>
	
   -­‐ms-­‐flex-­‐flow:	
  “”
	
   flex-­‐flow:	
  “”
}
You can also set flex-direction and flex-wrap as individual
properties if you wish.
Monday, July 22, 2013
Flexbox syntax
Controlling flex item flexibility
.flex-­‐item	
  {
	
   -­‐webkit-­‐flex:	
  none	
  |<flex-­‐grow>	
  <flex-­‐shrink>||	
  <flex-­‐basis>
	
   -­‐ms-­‐flex:	
  “”
	
   flex:	
  “”
}
I’m not going to lie... this takes some explaining...
Monday, July 22, 2013
Flexbox syntax
Flex: Flex Grow
.flex-­‐item	
  {
	
   -­‐webkit-­‐flex:	
  none	
  |<flex-­‐grow>	
  <flex-­‐shrink>||	
  <flex-­‐basis>
	
   -­‐ms-­‐flex:	
  “”
	
   flex:	
  “”
}
<number> Represents how much the flex item will grow relative to the
rest of the flex items in the container once positive space has been
distributed. If left out, it defaults to ‘1’
Monday, July 22, 2013
Flexbox syntax
Flex: Flex Shrink
.flex-­‐item	
  {
	
   -­‐webkit-­‐flex:	
  none	
  |<flex-­‐grow>	
  <flex-­‐shrink>||	
  <flex-­‐basis>
	
   -­‐ms-­‐flex:	
  “”
	
   flex:	
  “”
}
<number> Represents how much the flex item will shrink relative to
the rest of the flex items in the container once negative space has been
distributed. If left out, it defaults to ‘1’
Monday, July 22, 2013
Flexbox syntax
Flex: Flex Basis
.flex-­‐item	
  {
	
   -­‐webkit-­‐flex:	
  none	
  |<flex-­‐grow>	
  <flex-­‐shrink>||	
  <flex-­‐basis>
	
   -­‐ms-­‐flex:	
  “”
	
   flex:	
  “”
}
auto | <width> Represents the initial main size of a flex item, before
free space is distributed.When omitted, it defaults to ‘0’
Monday, July 22, 2013
Flexbox syntax
Common FlexValues
Flex: 0 auto initial
Equates to 0 1 auto. Sizes items based on width/height values. Item is inflexible but is
allowed to shrink to its min value
Flex: auto
Equates to 1 1 auto. Sizes items based on width/height values, but makes them fully
flexible to grow or shrink based on available space
Flex: none
Equates to 0 0 auto. Sizes items based on width/height values, but makes the item
totally inflexible.
Flex: <positive number>
Equates to <value> 1 0px. Makes the item flexible and sets the basis to 0.This
ensures the item receives the specified portion of free space available.
Monday, July 22, 2013
Flexbox syntax
Controlling display order
.flex-­‐item	
  {
	
   -­‐webkit-­‐order:	
  <integer>
	
   -­‐ms-­‐flex-­‐order:	
  “”
	
   order:	
  “”
}
Values start at ‘0’ and increments up. A negative value is displayed
before positive values.You can also reverse row and column direction.
Monday, July 22, 2013
Flexbox syntax
Controlling main axis alignment
.flex	
  {
-­‐webkit-­‐justify-­‐content:	
  flex-­‐start	
  |	
  flex-­‐end	
  |	
  center	
  |	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  space-­‐between	
  |	
  space-­‐around
-­‐ms-­‐flex-­‐pack:	
  start	
  |	
  end	
  |	
  center	
  |	
  justify
justify-­‐content:””
}
Axis alignment is performed after flexible lengths and auto margins
have been resolved.
Monday, July 22, 2013
Flexbox syntax
Controlling cross axis alignment
.flex	
  {
-­‐webkit-­‐align-­‐items:	
  flex-­‐start	
  |	
  flex-­‐end	
  |	
  center	
  |	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  baseline	
  |	
  stretch
-­‐ms-­‐flex-­‐align:	
  start	
  |	
  end	
  |	
  center	
  |	
  baseline	
  |	
  stretch
justify-­‐content:””
}
Align-items applies to all flex items in a container.To align a single item,
you can use the align-self property to a flex item and use the same values.
Monday, July 22, 2013
Flexbox syntax
Aligning multiple flex lines
.flex	
  {
-­‐webkit-­‐align-­‐content:	
  flex-­‐start	
  |	
  flex-­‐end	
  |	
  center	
  |	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  space-­‐between	
  |	
  space-­‐around	
  |	
  stretch
-­‐ms-­‐flex-­‐line-­‐pack:	
  start	
  |	
  end	
  |	
  center	
  |	
  justify	
  |	
  distribute	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  stretch
align-­‐content:””	
  }
Aligns multiple flex lines within a flex container. Has no effect on single
line flex containers.
Monday, July 22, 2013
Fantastic
Let’s see what it can do.
SP
Monday, July 22, 2013
Demo take-aways
Some things to remember:
Don’t overuse it
Let normal flow do the work where it makes sense
Think through your structure carefully
Defining regions and re-ordering content properly does
rely on structure, think these things through
Understand flex-basis
Knowing how an element’s main and cross size’s are
determined is crucial to achieving expected results
Don’t forget your margins
When setting alignments along axes, margins are taken
into account. Also, flex item margins don’t collapse.
Monday, July 22, 2013
So wait... is it the future or not?
Yes!... along with other emerging models
It’s great at 1D, OK at 2D
This makes Flexbox a great choice for UI elements,
application interfaces, and aligning/flexing items in
specific page regions
It’s not great at 3D or across page regions
CSS Grid Layout is a better choice for that
So what will we probably see?
Eventually I see Flexbox being used in conjunction with
other layout models to exact finer-grain control over
responsive elements
Monday, July 22, 2013
Go learn you some Flexbox
Go read the spec:
http://www.w3.org/TR/css3-flexbox/
Browser support:
http://caniuse.com/flexbox
Using Flexbox:
https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_flexible_boxes
Layout Nirvana?
http://dev.opera.com/articles/view/flexbox-basics/
CSS Flexbox First Look
http://www.lynda.com/CSS-tutorials/CSS-Flexbox-First-Look/116352-2.html
Want these slides?
http://www.slideshare.net/jameswillweb
Monday, July 22, 2013
THANK YOUTHANK YOUjames williamson | lynda.com
jwilliamson@lynda.com
@jameswillweb on the Twitter
www.simpleprimate.com
Want these slides?
http://www.slideshare.net/jameswillweb
Monday, July 22, 2013

Mais conteúdo relacionado

Semelhante a Is Flexbox the Future of Layout -bdconf

Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?jameswillweb
 
CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)Woodridge Software
 
Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!Scott Vandehey
 
Introduction to css flexbox
Introduction to css flexboxIntroduction to css flexbox
Introduction to css flexboxMarkandan R
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Zoe Gillenwater
 
Show & tell - Flex in flux
Show & tell - Flex in fluxShow & tell - Flex in flux
Show & tell - Flex in fluxDan Dineen
 
Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Zoe Gillenwater
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into PracticeZoe Gillenwater
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexboxmustafa sarac
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Zoe Gillenwater
 
Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Zoe Gillenwater
 
Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Zoe Gillenwater
 
Understanding the flex layout
Understanding the flex layoutUnderstanding the flex layout
Understanding the flex layoutBarak Drechsler
 
Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Zoe Gillenwater
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex LayoutNeha Sharma
 
Why you should consider Flexbox for your next project
Why you should consider Flexbox for your next projectWhy you should consider Flexbox for your next project
Why you should consider Flexbox for your next projectAnton Domratchev
 
Responsive design with flexbox
Responsive design with flexboxResponsive design with flexbox
Responsive design with flexboxMario Hernandez
 

Semelhante a Is Flexbox the Future of Layout -bdconf (20)

Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?
 
CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)
 
Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!
 
Introduction to css flexbox
Introduction to css flexboxIntroduction to css flexbox
Introduction to css flexbox
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)
 
Show & tell - Flex in flux
Show & tell - Flex in fluxShow & tell - Flex in flux
Show & tell - Flex in flux
 
Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into Practice
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexbox
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)
 
Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)
 
Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)
 
Understanding the flex layout
Understanding the flex layoutUnderstanding the flex layout
Understanding the flex layout
 
Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex Layout
 
A complete guide to flexbox
A complete guide to flexboxA complete guide to flexbox
A complete guide to flexbox
 
Flex Web Development.pdf
Flex Web Development.pdfFlex Web Development.pdf
Flex Web Development.pdf
 
Flex box
Flex boxFlex box
Flex box
 
Why you should consider Flexbox for your next project
Why you should consider Flexbox for your next projectWhy you should consider Flexbox for your next project
Why you should consider Flexbox for your next project
 
Responsive design with flexbox
Responsive design with flexboxResponsive design with flexbox
Responsive design with flexbox
 

Último

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Is Flexbox the Future of Layout -bdconf

  • 1. IS FLEXBOX THE FUTURE OF LAYOUT? IS FLEXBOX THE FUTURE OF LAYOUT? IS FLEXBOX THE FUTURE OF LAYOUT? james williamson | lynda.com Monday, July 22, 2013
  • 2. Hello. I’m JamesWilliamson happy to be here @jameswillweb on the Twitter | senior author Monday, July 22, 2013
  • 3. What are we going to talk about? Flexbox... and can it fix what’s wrong with CSS layout? Monday, July 22, 2013
  • 4. Be honest. How many techniques can you think of, just off the top of your head, for vertically centering something? How easy are they? I rest my case. CSS layout should be easier Monday, July 22, 2013
  • 5. Which brings us to Flexbox Flexbox allows us to control the size, order, and alignment of elements along multiple axes. Monday, July 22, 2013
  • 6. Why is it awesome? Some of the high points: It’s flexible! I mean, look at the name.You can easily make things stretch and flex to fit available space, great for responsive design. Easy alignment Horizontal, vertical, baseline... it’s all good. Source order independence You want that before this, but only when that? OK. Easy Syntax You can learn it in one afternoon. Monday, July 22, 2013
  • 7. pre 2008 CSS Working Group discusses proposing a Flexible Box Model similar to what is found in XUL and XAML. 2008 2009 2010 2011 2012 Before you use Flexbox, you need to know a little history Monday, July 22, 2013
  • 8. 2009 The Flexible Box Layout Module is published as a working draft. Chrome and Safari add partial support while Mozilla support relies on older XUL implementation.The syntax closely follows XUL flexbox syntax and is often referred to as “Flexbox 2009.” 2008 2009 2010 2011 2012 Before you use Flexbox, you need to know a little history Monday, July 22, 2013
  • 9. 2011 Tab Atkins takes over as editor for the Flexbox Spec and publishes two working drafts over the course of the year.These drafts re-write the syntax significantly and are sometimes referred to as “tweener” syntax. Chrome, Opera and & IE 10 begin to implement this syntax. 2008 2009 2010 2011 2012 Before you use Flexbox, you need to know a little history Monday, July 22, 2013
  • 10. 2012 Syntax is further changed and refined. Spec is now a Candidate Recommendation. Opera releases un-prefixed support, Chrome supports the current syntax in prefixed form, and IE 10 adds prefixed support for the “tweener” syntax. Mozilla is close to releasing unprefixed support. 2008 2009 2010 2011 2012 Before you use Flexbox, you need to know a little history Monday, July 22, 2013
  • 11. Why does this matter? In order to use Flexbox effectively, you’ll need to know who supports the 2009 syntax, the “tweener” syntax, the modern syntax, and when to use vendor prefixes. Monday, July 22, 2013
  • 12. So... how’s support? Browser Firefox  (older) Firefox Google  Chrome Safari Opera Internet  Explorer iOS  Safari Opera  Mini Opera  Mobile Android  Browser Chrome  for  Android Blackberry  Browser support 2.0+ 22+ 22+ 5.1+ 12.1+ 10+ 3.2 5  -­‐  7 12.0+ 2.1 27 10+ notes old  XUL  syntax with  -­‐webkit-­‐  prefix -­‐ms-­‐  prefix,  uses  tweener  syntax 2009  syntax 2009  syntax,  -­‐webkit-­‐  prefix with  -­‐webkit-­‐  prefix Wait....  what? 2012  syntax  supported                2009  syntax                nada                                                                        (as  of  07-­‐22-­‐13) Monday, July 22, 2013
  • 13. How does Flexbox work? Basic concepts: It’s a new layout mode Joins block, inline, table, and positioned Similar to block layout Containing elements are laid out in a flow direction Has super powers Flow direction can be up or down, left or right, display order can be reversed, elements can “flex” their size to respond to available space and align to their containers or other elements Monday, July 22, 2013
  • 14. How does Flexbox work? Basic steps: Define flex containers All direct child elements become flex items Establish flow direction Flex containers can flow either in a row or column and can be single or multiline Go crazy with the cheese whiz Flex items can now be spaced, flexed, aligned, or arranged as you see fit within the flow direction Monday, July 22, 2013
  • 15. How does Flexbox work? It’s all about the axis... er axes. flex itemflex item flex container main axis cross axis Monday, July 22, 2013
  • 16. Flexbox syntax* Defining flex containers .flex  {   display:  -­‐webkit-­‐flex;   display:  -­‐ms-­‐flexbox;   display:  flex; } *A note about syntax.I’ll be showing 2012 syntax including webkit prefixes,IE prefix (“tweener” syntax),and unprefixed syntax.I won’t show older (2009 syntax) or older -o- and -moz- prefixes (there’s also an inline-flex variation) Monday, July 22, 2013
  • 17. Flexbox syntax Setting flow direction and line wrap .flex  {   -­‐webkit-­‐flex-­‐flow:  <flex  direction>  |  <flex  wrap>   -­‐ms-­‐flex-­‐flow:  “”   flex-­‐flow:  “” } You can also set flex-direction and flex-wrap as individual properties if you wish. Monday, July 22, 2013
  • 18. Flexbox syntax Controlling flex item flexibility .flex-­‐item  {   -­‐webkit-­‐flex:  none  |<flex-­‐grow>  <flex-­‐shrink>||  <flex-­‐basis>   -­‐ms-­‐flex:  “”   flex:  “” } I’m not going to lie... this takes some explaining... Monday, July 22, 2013
  • 19. Flexbox syntax Flex: Flex Grow .flex-­‐item  {   -­‐webkit-­‐flex:  none  |<flex-­‐grow>  <flex-­‐shrink>||  <flex-­‐basis>   -­‐ms-­‐flex:  “”   flex:  “” } <number> Represents how much the flex item will grow relative to the rest of the flex items in the container once positive space has been distributed. If left out, it defaults to ‘1’ Monday, July 22, 2013
  • 20. Flexbox syntax Flex: Flex Shrink .flex-­‐item  {   -­‐webkit-­‐flex:  none  |<flex-­‐grow>  <flex-­‐shrink>||  <flex-­‐basis>   -­‐ms-­‐flex:  “”   flex:  “” } <number> Represents how much the flex item will shrink relative to the rest of the flex items in the container once negative space has been distributed. If left out, it defaults to ‘1’ Monday, July 22, 2013
  • 21. Flexbox syntax Flex: Flex Basis .flex-­‐item  {   -­‐webkit-­‐flex:  none  |<flex-­‐grow>  <flex-­‐shrink>||  <flex-­‐basis>   -­‐ms-­‐flex:  “”   flex:  “” } auto | <width> Represents the initial main size of a flex item, before free space is distributed.When omitted, it defaults to ‘0’ Monday, July 22, 2013
  • 22. Flexbox syntax Common FlexValues Flex: 0 auto initial Equates to 0 1 auto. Sizes items based on width/height values. Item is inflexible but is allowed to shrink to its min value Flex: auto Equates to 1 1 auto. Sizes items based on width/height values, but makes them fully flexible to grow or shrink based on available space Flex: none Equates to 0 0 auto. Sizes items based on width/height values, but makes the item totally inflexible. Flex: <positive number> Equates to <value> 1 0px. Makes the item flexible and sets the basis to 0.This ensures the item receives the specified portion of free space available. Monday, July 22, 2013
  • 23. Flexbox syntax Controlling display order .flex-­‐item  {   -­‐webkit-­‐order:  <integer>   -­‐ms-­‐flex-­‐order:  “”   order:  “” } Values start at ‘0’ and increments up. A negative value is displayed before positive values.You can also reverse row and column direction. Monday, July 22, 2013
  • 24. Flexbox syntax Controlling main axis alignment .flex  { -­‐webkit-­‐justify-­‐content:  flex-­‐start  |  flex-­‐end  |  center  |                                                                    space-­‐between  |  space-­‐around -­‐ms-­‐flex-­‐pack:  start  |  end  |  center  |  justify justify-­‐content:”” } Axis alignment is performed after flexible lengths and auto margins have been resolved. Monday, July 22, 2013
  • 25. Flexbox syntax Controlling cross axis alignment .flex  { -­‐webkit-­‐align-­‐items:  flex-­‐start  |  flex-­‐end  |  center  |                                                            baseline  |  stretch -­‐ms-­‐flex-­‐align:  start  |  end  |  center  |  baseline  |  stretch justify-­‐content:”” } Align-items applies to all flex items in a container.To align a single item, you can use the align-self property to a flex item and use the same values. Monday, July 22, 2013
  • 26. Flexbox syntax Aligning multiple flex lines .flex  { -­‐webkit-­‐align-­‐content:  flex-­‐start  |  flex-­‐end  |  center  |                                                space-­‐between  |  space-­‐around  |  stretch -­‐ms-­‐flex-­‐line-­‐pack:  start  |  end  |  center  |  justify  |  distribute                                          |  stretch align-­‐content:””  } Aligns multiple flex lines within a flex container. Has no effect on single line flex containers. Monday, July 22, 2013
  • 27. Fantastic Let’s see what it can do. SP Monday, July 22, 2013
  • 28. Demo take-aways Some things to remember: Don’t overuse it Let normal flow do the work where it makes sense Think through your structure carefully Defining regions and re-ordering content properly does rely on structure, think these things through Understand flex-basis Knowing how an element’s main and cross size’s are determined is crucial to achieving expected results Don’t forget your margins When setting alignments along axes, margins are taken into account. Also, flex item margins don’t collapse. Monday, July 22, 2013
  • 29. So wait... is it the future or not? Yes!... along with other emerging models It’s great at 1D, OK at 2D This makes Flexbox a great choice for UI elements, application interfaces, and aligning/flexing items in specific page regions It’s not great at 3D or across page regions CSS Grid Layout is a better choice for that So what will we probably see? Eventually I see Flexbox being used in conjunction with other layout models to exact finer-grain control over responsive elements Monday, July 22, 2013
  • 30. Go learn you some Flexbox Go read the spec: http://www.w3.org/TR/css3-flexbox/ Browser support: http://caniuse.com/flexbox Using Flexbox: https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_flexible_boxes Layout Nirvana? http://dev.opera.com/articles/view/flexbox-basics/ CSS Flexbox First Look http://www.lynda.com/CSS-tutorials/CSS-Flexbox-First-Look/116352-2.html Want these slides? http://www.slideshare.net/jameswillweb Monday, July 22, 2013
  • 31. THANK YOUTHANK YOUjames williamson | lynda.com jwilliamson@lynda.com @jameswillweb on the Twitter www.simpleprimate.com Want these slides? http://www.slideshare.net/jameswillweb Monday, July 22, 2013