Slide 1

Slide 1 text

FLEXBOX AND GRID LAYOUT

Slide 2

Slide 2 text

Diego Eis I love work with web. And I lost 50 pounds. ;-) @diegoeis @tableless http://tableless.com.br http://medium.com/@diegoeis http://slideshare.net/diegoeis

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

http://bit.ly / livro-como-ser-frontend

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

LOCAWEB OPEN SOURCE opensource.locaweb.com.br

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Gambi. Until now we only used Macgyver ways to structure layouts.

Slide 9

Slide 9 text

Table Tables made history. They changed the way how we show and structure content in the websites, but…

Slide 10

Slide 10 text

Column 1 Good article Column 2 X

Slide 11

Slide 11 text

No semantic.

Slide 12

Slide 12 text

Float Float give us some flexibility, but…

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Float affect other elements Forcing you to use other properties and techniques to solve some problems: clearfix, overflow, faux columns, double margins (old ie) etc etc etc…

Slide 15

Slide 15 text

Float depends of HTML structure You need to put the HTML elements in right place and order to make this right.

Slide 16

Slide 16 text

How to solve the problem of structuring layouts?

Slide 17

Slide 17 text

Three solutions to different problems • Grid Layout to structure parent elements. • Flexbox to control the struture of childs. • Template Layout to control the flow of content.

Slide 18

Slide 18 text

Template Layout At the moment, it defines a typographic grid for CSS. It has features to set up a grid-based template, to style the slots of the template and to flow content into them.

Slide 19

Slide 19 text

Today, let’s talk about Grid Layout and Flexbox

Slide 20

Slide 20 text

Grid Layout This CSS module defines a two-dimensional grid- based layout system, optimised for user interface design. In the grid layout model, the children of a grid container can be positioned into arbitrary slots in a flexible or fixed predefined layout grid.

Slide 21

Slide 21 text

Grid terminology

Slide 22

Slide 22 text

A grid container establishes a new grid formatting context for its contents. Grid container

Slide 23

Slide 23 text

Grid lines are horizontal or vertical lines between grid cells. They can be named or referred by numbers. The highlighted line in the image is the column line 2. Grid lines

Slide 24

Slide 24 text

It is the space between two adjacent row and two adjacent column grid lines. It is the smallest unit of the grid that can be referenced when positioning grid items Grid cell

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

.main { // Enable the grid space display: grid; } grid-template-rows: auto 20px auto; grid-template-columns: 250px 20px auto;

Slide 27

Slide 27 text

grid-template-rows: auto 20px auto; auto 20px auto grid-template-columns: 250px 20px auto; 250px 20px auto 1 2 3 4 1 2 3 4

Slide 28

Slide 28 text

header { grid-row: 1 / 2; grid-column: 1 / 4; } 1 2 1 2 1 4 1 4

Slide 29

Slide 29 text

aside { grid-row: 3 / 4; grid-column: 1 / 2; } 3 4 3 4 1 2 1 2

Slide 30

Slide 30 text

.content { grid-row: 3 / 4; grid-column: 3 / 4; } 3 4 3 4 3 4 3 4

Slide 31

Slide 31 text

header content sidebar

Slide 32

Slide 32 text

.main { display: grid; grid-template-rows: auto 20px auto; grid-template-columns: 250px 20px auto; } grid-template-areas: “header header header" “. . .” “sidebar . article”

Slide 33

Slide 33 text

header { grid-area: header; } aside { grid-area: sidebar; } article { grid-area: article; }

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

http://gridbyexample.com

Slide 36

Slide 36 text

Flexbox Flexbox define how the childs will fill the blank space available of parent element.

Slide 37

Slide 37 text

Flex Container First, we need to know the context where the flex items will work. The field where we will work is called Flex Container.

Slide 38

Slide 38 text

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes

Slide 39

Slide 39 text

flex-direction Define flow of the flex items placed in flex container.

Slide 40

Slide 40 text

item 1 item 2 item 3 row default row-reverse flex-direction item 3 item 2 item 1

Slide 41

Slide 41 text

item 3 item 2 item 1 with float… float: right; float: left;

Slide 42

Slide 42 text

item 3 column column-reverse flex-direction item 2 item 1 item 1 item 2 item 3

Slide 43

Slide 43 text

flex-wrap Define if the flex items will break onto multiple lines if their width are larger than width of container.

Slide 44

Slide 44 text

nowrap default item 1 item 2 item 3 wrap item 1 item 2 item 3 wrap-reverse item 3 item 2 item 1

Slide 45

Slide 45 text

justify-content Determine align of flex items in main-axis (horizontal line).

Slide 46

Slide 46 text

item 1 item 2 item 3 flex-start default justify-content item 1 item 2 item 3 flex-end item 1 item 2 item 3 center

Slide 47

Slide 47 text

item 1 item 2 item 3 space-around justify-content item 1 item 2 item 3 space-between

Slide 48

Slide 48 text

align-items Determine align of flex items in cross-axis (vertical line).

Slide 49

Slide 49 text

item 1 item 2 item 3 stretch default align-items center item 1 item 2 item 3

Slide 50

Slide 50 text

flex-start align-items flex-end item 1 item 2 item 3 item 1 item 2 item 3

Slide 51

Slide 51 text

baseline align-items item 1 item 2 item 3

Slide 52

Slide 52 text

align-content Align flex items with extra space on the cross-axis, within the flex container when have multiple lines.

Slide 53

Slide 53 text

stretch align-content item 1 flex-start item 1 item 2 item 3 item 4 item 3 item 2 item 4

Slide 54

Slide 54 text

flex-end align-content item 1 item 2 item 3 item 4 center item 1 item 2 item 3 item 4

Slide 55

Slide 55 text

space-around align-content item 1 item 2 item 3 item 4 space-between item 1 item 2 item 3 item 4

Slide 56

Slide 56 text

Flex Items

Slide 57

Slide 57 text

order Man, this is magic. This is awesome. This is “chuchu beleza”.

Slide 58

Slide 58 text

item 3 item 1 item 2 .item1 { order: 2; } .item2 { order: 3; } .item3 { order: 1; }

Slide 59

Slide 59 text

flex-grow Define how much the item will take of available space. The value serves as a proportion. If all elements have 1 of value, all elements will have same width. If one element have 2 of value, that element will have the double of size.

Slide 60

Slide 60 text

item 2 item 3 .item2 { flex-grow: 2; } item 1

Slide 61

Slide 61 text

flex-shrink Define how much the item will shrink.

Slide 62

Slide 62 text

item 2 .item2 { flex-shrink: 2; } item 3 item 1

Slide 63

Slide 63 text

flex-basis Define the width of elements. This is works like max-width.

Slide 64

Slide 64 text

item 1 item 2 item 3 .item { flex-basis: 100%; } item 1 .item { flex-basis: 100px; } item 2 item 3

Slide 65

Slide 65 text

flex Shorthand that make all the magic.

Slide 66

Slide 66 text

item 1 item 2 item 3 .item { flex: 1; } .item { flex-grow: 1; flex-shrink: 1; flex-basis: auto; }

Slide 67

Slide 67 text

DEMO

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

http://flexiejs.com

Slide 70

Slide 70 text

philipwalton.github.io/solved-by-flexbox

Slide 71

Slide 71 text

Goodbye! Let me know what you think! @diegoeis @tableless http://tableless.com.br http://medium.com/@diegoeis http://slideshare.net/diegoeis