Slide 1

Slide 1 text

Flexbox ONE GIANT LEAP FOR WEB LAYOUT STEPHEN HAY BDCONF, NASHVILLE 2013

Slide 2

Slide 2 text

The design-in-the-browser hamburger

Slide 3

Slide 3 text

DESIGNER The design-in-the-browser hamburger

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

DESIGNER The design-in-the-browser hamburger MAGIC CODE

Slide 9

Slide 9 text

Designers aren’t stupid.

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

image: NASA

Slide 12

Slide 12 text

~8 years image: NASA

Slide 13

Slide 13 text

https://en.wikipedia.org/wiki/File:First_Web_Server.jpg ~1 year

Slide 14

Slide 14 text

CASCADING STYLE SHEETS, LEVEL 1 ~2 years

Slide 15

Slide 15 text

17 years CSS has been around for

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

“Layout is hard.”

Slide 18

Slide 18 text

image: NASA

Slide 19

Slide 19 text

“Layout solutions are an interesting area in CSS to me.” – Tab Atkins

Slide 20

Slide 20 text

http://dev.w3.org/csswg/css-flexbox/ We’re talking about this version

Slide 21

Slide 21 text

Two major types of “real” web layout

Slide 22

Slide 22 text

Two major types of “real” web layout

Slide 23

Slide 23 text

Available space Flexbox helps us deal with even when we don’t know what that will be

Slide 24

Slide 24 text

alignment Flexbox helps us with both horizontally and vertically

Slide 25

Slide 25 text

ordre Flexbox helps us with display

Slide 26

Slide 26 text

A quick introduction to Flexbox Terminology Axes & Size Flex Alignment Order

Slide 27

Slide 27 text

Leave your layout baggage at the door.

Slide 28

Slide 28 text

Terminology Flex containers Flex items Main axis / size / dimension Cross axis / size / dimension Start / end

Slide 29

Slide 29 text

CODE http://www.flickr.com/photos/evdaimon/337754011/

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

display: flex | inline-flex

Slide 32

Slide 32 text

Hi, Bob. #bob { display: flex; } (Bob is a flex container) display: flex | inline-flex

Slide 33

Slide 33 text

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!

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Main axis + main size, main dimension in the case of flex-direction: row

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Start & End depends on direction CROSS START CROSS END MAIN END CENTER MAIN START in the case of flex-direction: row

Slide 38

Slide 38 text

Start & End depends on direction MAIN START MAIN END CROSS END CENTER CROSS START in the case of flex-direction: column

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Flex .foo { flex: initial; } .foo { flex: 0 1 auto;} IS EQUIVALENT TO: common values (1) width: 150px width: 150px width: 150px

Slide 43

Slide 43 text

Flex .foo { flex: auto; } .foo { flex: 1 1 auto;} IS EQUIVALENT TO: common values (2) width: 150px width: 150px width: 150px

Slide 44

Slide 44 text

Flex .foo { flex: none; } .foo { flex: 0 0 auto;} IS EQUIVALENT TO: common values (3) width: 150px width: 150px width: 150px

Slide 45

Slide 45 text

Flex .foo { flex: [n]; } .foo { flex: [n] 1 0%;} IS EQUIVALENT TO: common values (4) flex: 1 flex: 1 flex: 1

Slide 46

Slide 46 text

Flex flex: [n] flex: 1 flex: 1 flex: 2

Slide 47

Slide 47 text

Flex flex: [n] flex: 1 flex: 5 flex: 2

Slide 48

Slide 48 text

Alignment auto-margins margin-top: auto no margin no margin .foo { margin-top: auto; }

Slide 49

Slide 49 text

Alignment along the main axis: justify-content (align-content for multiple lines along cross axis) JUSTIFY-CONTENT #bob { justify-content: flex-start | flex-end | center | space-between | space-around } in the case of flex-direction: row

Slide 50

Slide 50 text

http://dev.w3.org/csswg/css-flexbox/

Slide 51

Slide 51 text

http://dev.w3.org/csswg/css-flexbox/

Slide 52

Slide 52 text

Alignment along the cross axis: align-items (align-self can be applied to the flex items themselves/individually) ALIGN-ITEMS #bob { align-items: flex-start | flex-end | center | baseline | stretch } in the case of flex-direction: row

Slide 53

Slide 53 text

http://dev.w3.org/csswg/css-flexbox/

Slide 54

Slide 54 text

Order changes the visual order vs. the source order 3 1 2 .item:nth-child(3) { order: -1; } .foo { order: [n]; }

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

A small example

Slide 57

Slide 57 text

Structured content

Slide 58

Slide 58 text

Basic styles

Slide 59

Slide 59 text

display:flex on container

Slide 60

Slide 60 text

flex-direction:column

Slide 61

Slide 61 text

margin-auto on icons and form

Slide 62

Slide 62 text

flex:1 on input field

Slide 63

Slide 63 text

order for avatar display

Slide 64

Slide 64 text

done.

Slide 65

Slide 65 text

Browser compatibility source: http://beta.caniuse.com/#search=flexbox

Slide 66

Slide 66 text

Don’t sweat the prefixes http://leaverou.github.io/prefixfree/

Slide 67

Slide 67 text

meh. source: http://coding.smashingmagazine.com/2013/05/22/centering-elements-with-flexbox/ (but go ahead if you really want to)

Slide 68

Slide 68 text

http://coding.smashingmagazine.com/2013/05/22/centering-elements-with-flexbox/ Syntax variations

Slide 69

Slide 69 text

Before you get all excited…

Slide 70

Slide 70 text

http://www.xanthir.com/blog/b4580 Flexboxes aren’t ideal for page layout

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

The hardest thing to learn about new tools is not how to use them, but when to use them.

Slide 74

Slide 74 text

have fun keep learning THANK YOU! @stephenhay