Flexbox and Grid Layout: How you will structure layouts tomorrow.

71
FLEXBOX AND GRID LAYOUT

Transcript of Flexbox and Grid Layout: How you will structure layouts tomorrow.

Page 1: Flexbox and Grid Layout: How you will structure layouts tomorrow.

FLEXBOX AND GRID LAYOUT

Page 2: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Diego EisI love work with web. And I lost 50 pounds. ;-)

@diegoeis @tableless

http://tableless.com.br http://medium.com/@diegoeis http://slideshare.net/diegoeis

Page 3: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 4: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 5: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 6: Flexbox and Grid Layout: How you will structure layouts tomorrow.

LOCAWEBOPEN SOURCE

opensource.locaweb.com.br

Page 7: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 8: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 9: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 10: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Column 1 Good article Column 2

X

Page 11: Flexbox and Grid Layout: How you will structure layouts tomorrow.

No semantic.

Page 12: Flexbox and Grid Layout: How you will structure layouts tomorrow.

FloatFloat give us some flexibility, but…

Page 13: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 14: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 15: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 16: Flexbox and Grid Layout: How you will structure layouts tomorrow.

How to solve the problem of structuring layouts?

Page 17: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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.

Page 18: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Template LayoutAt 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.

Page 19: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Today, let’s talk about Grid Layout and Flexbox

Page 20: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Grid LayoutThis 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.

Page 21: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Grid terminology

Page 22: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Grid container

Page 23: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 24: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 25: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 26: Flexbox and Grid Layout: How you will structure layouts tomorrow.

.main {

// Enable the grid spacedisplay: grid;

}

grid-template-rows: auto 20px auto;grid-template-columns: 250px 20px auto;

Page 27: Flexbox and Grid Layout: How you will structure layouts tomorrow.

grid-template-rows: auto 20px auto;

auto20px

auto

grid-template-columns: 250px 20px auto;

250px

20px

auto

1

2

3

4

1 2 3 4

Page 28: Flexbox and Grid Layout: How you will structure layouts tomorrow.

header {

grid-row: 1 / 2;

grid-column: 1 / 4;

}

1

2

1 2

1 4

1 4

Page 29: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

3

4

3 4

1

2

1 2

Page 30: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

3

4

3 4

3

4

3 4

Page 31: Flexbox and Grid Layout: How you will structure layouts tomorrow.

header

contentsidebar

Page 32: Flexbox and Grid Layout: How you will structure layouts tomorrow.

.main {

display: grid;grid-template-rows: auto 20px auto;grid-template-columns: 250px 20px auto;

}

grid-template-areas: “header header header"

“. . .”

“sidebar . article”

Page 33: Flexbox and Grid Layout: How you will structure layouts tomorrow.

header {grid-area: header;

}

aside {grid-area: sidebar;

}

article {grid-area: article;

}

Page 34: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 35: Flexbox and Grid Layout: How you will structure layouts tomorrow.

http://gridbyexample.com

Page 36: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 37: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 38: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 39: Flexbox and Grid Layout: How you will structure layouts tomorrow.

flex-directionDefine flow of the flex items placed in flex container.

Page 40: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 1 item 2 item 3

row default

row-reverse

flex-direction

item 3 item 2 item 1

Page 41: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 3 item 2 item 1

with float…

float: right; float: left;

Page 42: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 3

column column-reverse

flex-direction

item 2

item 1

item 1

item 2

item 3

Page 43: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 44: Flexbox and Grid Layout: How you will structure layouts tomorrow.

nowrap default

item 1 item 2 item 3

wrap

item 1 item 2

item 3

wrap-reverse

item 3 item 2

item 1

Page 45: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 46: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 47: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 1 item 2 item 3

space-around

justify-content

item 1 item 2 item 3

space-between

Page 48: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 49: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 1 item 2 item 3

stretch default

align-items

center

item 1 item 2 item 3

Page 50: Flexbox and Grid Layout: How you will structure layouts tomorrow.

flex-start

align-items

flex-end

item 1 item 2 item 3

item 1 item 2 item 3

Page 51: Flexbox and Grid Layout: How you will structure layouts tomorrow.

baseline

align-items

item 1 item 2 item 3

Page 52: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 53: Flexbox and Grid Layout: How you will structure layouts tomorrow.

stretch

align-content

item 1

flex-start

item 1 item 2

item 3 item 4

item 3

item 2

item 4

Page 54: Flexbox and Grid Layout: How you will structure layouts tomorrow.

flex-end

align-content

item 1 item 2

item 3 item 4

center

item 1 item 2

item 3 item 4

Page 55: Flexbox and Grid Layout: How you will structure layouts tomorrow.

space-around

align-content

item 1 item 2

item 3 item 4

space-between

item 1 item 2

item 3 item 4

Page 56: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Flex Items

Page 57: Flexbox and Grid Layout: How you will structure layouts tomorrow.

orderMan, this is magic. This is awesome. This is “chuchu beleza”.

Page 58: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 3 item 1 item 2

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

Page 59: Flexbox and Grid Layout: How you will structure layouts tomorrow.

flex-growDefine 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.

Page 60: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 2 item 3

.item2 { flex-grow: 2; }

item 1

Page 61: Flexbox and Grid Layout: How you will structure layouts tomorrow.

flex-shrinkDefine how much the item will shrink.

Page 62: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 2

.item2 { flex-shrink: 2; }

item 3item 1

Page 63: Flexbox and Grid Layout: How you will structure layouts tomorrow.

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

Page 64: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 1 item 2 item 3

.item { flex-basis: 100%; }

item 1

.item { flex-basis: 100px; }

item 2 item 3

Page 65: Flexbox and Grid Layout: How you will structure layouts tomorrow.

flexShorthand that make all the magic.

Page 66: Flexbox and Grid Layout: How you will structure layouts tomorrow.

item 1 item 2 item 3

.item { flex: 1; }

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

}

Page 67: Flexbox and Grid Layout: How you will structure layouts tomorrow.

DEMO

Page 68: Flexbox and Grid Layout: How you will structure layouts tomorrow.
Page 69: Flexbox and Grid Layout: How you will structure layouts tomorrow.

http://flexiejs.com

Page 70: Flexbox and Grid Layout: How you will structure layouts tomorrow.

philipwalton.github.io/solved-by-flexbox

Page 71: Flexbox and Grid Layout: How you will structure layouts tomorrow.

Goodbye!Let me know what you think!

@diegoeis @tableless

http://tableless.com.br http://medium.com/@diegoeis http://slideshare.net/diegoeis