SlideShare a Scribd company logo
1 of 34
Download to read offline
IS FLEXBOX
THE FUTURE OF LAYOUT?
    james williamson | lynda.com
Hello.
I’m James Williamson

                  | senior author

       happy to be here

  @jameswillweb on the Twitter
What are we going
 to talk about?
 Flexbox... and can it fix what’s
    wrong with CSS layout?
So wait... what’s wrong
      with layout now?
Let’s take a look at the evolution of CSS layout:
      no layout
         We just let normal flow do its thing

      tables
         For you youngsters.... seriously, we used to do this

      box model / positioning / floats / cursing
         Progress! Still, much like tables, we’re still hacking...
Things that should be
    simple aren’t
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.
Which brings us to Flexbox

  In the flex layout model, the children of a flex container can be laid out in any
  direction, and can "flex" their sizes, either growing to fill unused space or
  shrinking to avoid overflowing the parent. Both horizontal and vertical
  alignment of the children can be easily manipulated. Nesting of these boxes
  (horizontal inside vertical, or vertical inside horizontal) can be used to build
  layouts in two dimensions.



                                     ― CSS Flexible Box Layout Module
What’s so great about
           Flexbox?
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

       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.
Sounds awesome! So...is
Flexbox the future of layout?


             No.
        Thanks for coming.
Sounds awesome! So...is
Flexbox the future of layout?

   OK, just kidding (sort of). The
     answer is both Yes & No!
First, a little history...
         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
First, a little history...
         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
First, a little history...
         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
First, a little history...
         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
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
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
How does Flexbox work?
             It’s all about the axis... er axes.

                         main axis




        flex item       flex item

cross axis                                         flex container
Flexbox syntax*
Defining flex containers
 .flex	
  {
 	
   display:	
  -­‐webkit-­‐flex;
 	
   display:	
  -­‐ms-­‐flexbox;
 	
   display:	
  flex;
 }


                     (there’s also an inline-flex variation)




                     *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
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.
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...
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’
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’
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’
Flexbox syntax
Common Flex Values
  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.
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.
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.
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.
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.
Fantastic


         SP
Let’s take it for a spin.
Demo Time


                 SP
If you’re viewing this slide deck later,
this is where the cool stuff happened.
                Sorry.
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.
So... how’s support?
Browser                 support            notes
Firefox                    2.0+            new	
  syntax	
  unprefixed	
  in	
  nightly
Google	
  Chrome           22+             with	
  -­‐webkit-­‐	
  prefix
Safari                     5.1+
Opera                      12.1+
Internet	
  Explorer       10+             -­‐ms-­‐	
  prefix,	
  uses	
  tweener	
  syntax
iOS	
  Safari              3.2             2009	
  syntax
Opera	
  Mini              5	
  -­‐	
  7
Opera	
  Mobile            12.0+
Android	
  Browser         2.1             2009	
  syntax,	
  -­‐webkit-­‐	
  prefix
Blackberry	
  Browser      10+             Wait....	
  what?


                                                               2012	
  syntax	
  supported
                                                               2009	
  syntax
                                                               nada

                                                                            (as of 12-05-12)
So wait... is it the future or not?
 Of course... 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
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/

Flexbox Please!
 http://demo.agektmr.com/flexbox/

Want these slides?
 http://www.slideshare.net/jameswillweb/presentations
THANK YOU
james williamson | lynda.com
   jwilliamson@lynda.com
 @jameswillweb on the Twitter
   www.simpleprimate.com

More Related Content

Similar to Is Flexbox the Future of Layout?

Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!Scott Vandehey
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexboxmustafa sarac
 
CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)Woodridge Software
 
Show & tell - Flex in flux
Show & tell - Flex in fluxShow & tell - Flex in flux
Show & tell - Flex in fluxDan Dineen
 
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
 
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)Stephen Hay
 
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
 
Is Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfIs Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfjameswillweb
 
Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Zoe Gillenwater
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex LayoutNeha Sharma
 
Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Zoe Gillenwater
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfKaty Slemon
 
Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Zoe Gillenwater
 
Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Zoe Gillenwater
 
CSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignCSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignArash Milani
 

Similar to Is Flexbox the Future of Layout? (20)

Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexbox
 
CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)CSS Flexbox (flexible box layout)
CSS Flexbox (flexible box layout)
 
Show & tell - Flex in flux
Show & tell - Flex in fluxShow & tell - Flex in flux
Show & tell - Flex in flux
 
Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)
 
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)
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)
 
A complete guide to flexbox
A complete guide to flexboxA complete guide to flexbox
A complete guide to flexbox
 
Is Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfIs Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconf
 
Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex Layout
 
Layout with flexbox
Layout with flexboxLayout with flexbox
Layout with flexbox
 
Flex Web Development.pdf
Flex Web Development.pdfFlex Web Development.pdf
Flex Web Development.pdf
 
Flex box
Flex boxFlex box
Flex box
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)
 
Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)
 
CSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignCSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive Design
 

More from jameswillweb

A Web for Everyone
A Web for EveryoneA Web for Everyone
A Web for Everyonejameswillweb
 
Hooray Icon Fonts! Artifact Conference
Hooray Icon Fonts! Artifact ConferenceHooray Icon Fonts! Artifact Conference
Hooray Icon Fonts! Artifact Conferencejameswillweb
 
Hooray Icon Fonts workshop
Hooray Icon Fonts workshopHooray Icon Fonts workshop
Hooray Icon Fonts workshopjameswillweb
 
Hooray Icon Fonts!
Hooray Icon Fonts!Hooray Icon Fonts!
Hooray Icon Fonts!jameswillweb
 
Developing Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CCDeveloping Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CCjameswillweb
 
Designing Responsively with Dreamweaver
Designing Responsively with DreamweaverDesigning Responsively with Dreamweaver
Designing Responsively with Dreamweaverjameswillweb
 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devicesjameswillweb
 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devicesjameswillweb
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oiljameswillweb
 

More from jameswillweb (9)

A Web for Everyone
A Web for EveryoneA Web for Everyone
A Web for Everyone
 
Hooray Icon Fonts! Artifact Conference
Hooray Icon Fonts! Artifact ConferenceHooray Icon Fonts! Artifact Conference
Hooray Icon Fonts! Artifact Conference
 
Hooray Icon Fonts workshop
Hooray Icon Fonts workshopHooray Icon Fonts workshop
Hooray Icon Fonts workshop
 
Hooray Icon Fonts!
Hooray Icon Fonts!Hooray Icon Fonts!
Hooray Icon Fonts!
 
Developing Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CCDeveloping Modern Web Interfaces with Dreamweaver CC
Developing Modern Web Interfaces with Dreamweaver CC
 
Designing Responsively with Dreamweaver
Designing Responsively with DreamweaverDesigning Responsively with Dreamweaver
Designing Responsively with Dreamweaver
 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
 
Optimizing Sites for Mobile Devices
Optimizing Sites for Mobile DevicesOptimizing Sites for Mobile Devices
Optimizing Sites for Mobile Devices
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
 

Recently uploaded

Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...ZurliaSoop
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...Nitya salvi
 
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证wpkuukw
 
Sweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptxSweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptxbingyichin04
 
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...samsungultra782445
 
Gamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad IbrahimGamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad Ibrahimamgadibrahim92
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...instagramfab782445
 
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best ServiceIndependent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for FriendshipRaebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for FriendshipNitya salvi
 
一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证
一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证
一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证eqaqen
 
Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...
Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...
Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...drmarathore
 
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证eeanqy
 
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Nitya salvi
 
How to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdfHow to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdfOffice Furniture Plus - Irving
 
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime PondicherryPondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherrymeghakumariji156
 
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...Amil baba
 
Essential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive GuideEssential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive GuideDesign Studio UI UX
 
Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...gajnagarg
 

Recently uploaded (20)

Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
Jual Obat Aborsi Bandung ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan ...
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
Just Call Vip call girls Kasganj Escorts ☎️8617370543 Two shot with one girl ...
 
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
 
Sweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptxSweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptx
 
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
 
Hackathon evaluation template_latest_uploadpdf
Hackathon evaluation template_latest_uploadpdfHackathon evaluation template_latest_uploadpdf
Hackathon evaluation template_latest_uploadpdf
 
Gamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad IbrahimGamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad Ibrahim
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
 
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best ServiceIndependent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
 
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for FriendshipRaebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
 
一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证
一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证
一比一定(购)西悉尼大学毕业证(WSU毕业证)成绩单学位证
 
Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...
Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...
Abortion pills in Kuwait 🚚+966505195917 but home delivery available in Kuwait...
 
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
怎样办理巴斯大学毕业证(Bath毕业证书)成绩单留信认证
 
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
 
How to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdfHow to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdf
 
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime PondicherryPondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
 
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
 
Essential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive GuideEssential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive Guide
 
Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Meerut [ 7014168258 ] Call Me For Genuine Models We...
 

Is Flexbox the Future of Layout?

  • 1. IS FLEXBOX THE FUTURE OF LAYOUT? james williamson | lynda.com
  • 2. Hello. I’m James Williamson | senior author happy to be here @jameswillweb on the Twitter
  • 3. What are we going to talk about? Flexbox... and can it fix what’s wrong with CSS layout?
  • 4. So wait... what’s wrong with layout now? Let’s take a look at the evolution of CSS layout: no layout We just let normal flow do its thing tables For you youngsters.... seriously, we used to do this box model / positioning / floats / cursing Progress! Still, much like tables, we’re still hacking...
  • 5. Things that should be simple aren’t 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.
  • 6. Which brings us to Flexbox In the flex layout model, the children of a flex container can be laid out in any direction, and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions. ― CSS Flexible Box Layout Module
  • 7. What’s so great about Flexbox? 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 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.
  • 8. Sounds awesome! So...is Flexbox the future of layout? No. Thanks for coming.
  • 9. Sounds awesome! So...is Flexbox the future of layout? OK, just kidding (sort of). The answer is both Yes & No!
  • 10. First, a little history... 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
  • 11. First, a little history... 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
  • 12. First, a little history... 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
  • 13. First, a little history... 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
  • 14. 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
  • 15. 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
  • 16. How does Flexbox work? It’s all about the axis... er axes. main axis flex item flex item cross axis flex container
  • 17. Flexbox syntax* Defining flex containers .flex  {   display:  -­‐webkit-­‐flex;   display:  -­‐ms-­‐flexbox;   display:  flex; } (there’s also an inline-flex variation) *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
  • 18. 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.
  • 19. 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...
  • 20. 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’
  • 21. 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’
  • 22. 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’
  • 23. Flexbox syntax Common Flex Values 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.
  • 24. 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.
  • 25. 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.
  • 26. 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.
  • 27. 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.
  • 28. Fantastic SP Let’s take it for a spin.
  • 29. Demo Time SP If you’re viewing this slide deck later, this is where the cool stuff happened. Sorry.
  • 30. 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.
  • 31. So... how’s support? Browser support notes Firefox 2.0+ new  syntax  unprefixed  in  nightly Google  Chrome 22+ with  -­‐webkit-­‐  prefix Safari 5.1+ Opera 12.1+ Internet  Explorer 10+ -­‐ms-­‐  prefix,  uses  tweener  syntax iOS  Safari 3.2 2009  syntax Opera  Mini 5  -­‐  7 Opera  Mobile 12.0+ Android  Browser 2.1 2009  syntax,  -­‐webkit-­‐  prefix Blackberry  Browser 10+ Wait....  what? 2012  syntax  supported 2009  syntax nada (as of 12-05-12)
  • 32. So wait... is it the future or not? Of course... 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
  • 33. 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/ Flexbox Please! http://demo.agektmr.com/flexbox/ Want these slides? http://www.slideshare.net/jameswillweb/presentations
  • 34. THANK YOU james williamson | lynda.com jwilliamson@lynda.com @jameswillweb on the Twitter www.simpleprimate.com