Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

7,759 views

Published on

Say goodby to Float. Float save us until today. But float was never the right solution. With Flexbox and Grid Layout, we have the right solutions (maybe) to structure layouts to many devices and screens, with less work, easy (not so much) to understand syntax and maintainable code.

Lets talk today about Flexbox and Grid Layout and how they work.

Published in: Technology

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

  1. 1. FLEXBOX AND GRID LAYOUT
  2. 2. 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
  3. 3. http://bit.ly / livro-como-ser-frontend
  4. 4. LOCAWEB OPEN SOURCE opensource.locaweb.com.br
  5. 5. Gambi. Until now we only used Macgyver ways to structure layouts.
  6. 6. Table Tables made history. They changed the way how we show and structure content in the websites, but…
  7. 7. Column 1 Good article Column 2 X
  8. 8. No semantic.
  9. 9. Float Float give us some flexibility, but…
  10. 10. 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…
  11. 11. Float depends of HTML structure You need to put the HTML elements in right place and order to make this right.
  12. 12. How to solve the problem of structuring layouts?
  13. 13. 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.
  14. 14. 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.
  15. 15. Today, let’s talk about Grid Layout and Flexbox
  16. 16. 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.
  17. 17. Grid terminology
  18. 18. A grid container establishes a new grid formatting context for its contents. Grid container
  19. 19. 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
  20. 20. 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
  21. 21. .main { // Enable the grid space display: grid; } grid-template-rows: auto 20px auto; grid-template-columns: 250px 20px auto;
  22. 22. 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
  23. 23. header { grid-row: 1 / 2; grid-column: 1 / 4; } 1 2 1 2 1 4 1 4
  24. 24. aside { grid-row: 3 / 4; grid-column: 1 / 2; } 3 4 3 4 1 2 1 2
  25. 25. .content { grid-row: 3 / 4; grid-column: 3 / 4; } 3 4 3 4 3 4 3 4
  26. 26. header contentsidebar
  27. 27. .main { display: grid; grid-template-rows: auto 20px auto; grid-template-columns: 250px 20px auto; } grid-template-areas: “header header header" “. . .” “sidebar . article”
  28. 28. header { grid-area: header; } aside { grid-area: sidebar; } article { grid-area: article; }
  29. 29. http://gridbyexample.com
  30. 30. Flexbox Flexbox define how the childs will fill the blank space available of parent element.
  31. 31. 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.
  32. 32. https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes
  33. 33. flex-direction Define flow of the flex items placed in flex container.
  34. 34. item 1 item 2 item 3 row default row-reverse flex-direction item 3 item 2 item 1
  35. 35. item 3 item 2 item 1 with float… float: right; float: left;
  36. 36. item 3 column column-reverse flex-direction item 2 item 1 item 1 item 2 item 3
  37. 37. flex-wrap Define if the flex items will break onto multiple lines if their width are larger than width of container.
  38. 38. nowrap default item 1 item 2 item 3 wrap item 1 item 2 item 3 wrap-reverse item 3 item 2 item 1
  39. 39. justify-content Determine align of flex items in main-axis (horizontal line).
  40. 40. 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
  41. 41. item 1 item 2 item 3 space-around justify-content item 1 item 2 item 3 space-between
  42. 42. align-items Determine align of flex items in cross-axis (vertical line).
  43. 43. item 1 item 2 item 3 stretch default align-items center item 1 item 2 item 3
  44. 44. flex-start align-items flex-end item 1 item 2 item 3 item 1 item 2 item 3
  45. 45. baseline align-items item 1 item 2 item 3
  46. 46. align-content Align flex items with extra space on the cross-axis, within the flex container when have multiple lines.
  47. 47. stretch align-content item 1 flex-start item 1 item 2 item 3 item 4 item 3 item 2 item 4
  48. 48. flex-end align-content item 1 item 2 item 3 item 4 center item 1 item 2 item 3 item 4
  49. 49. space-around align-content item 1 item 2 item 3 item 4 space-between item 1 item 2 item 3 item 4
  50. 50. Flex Items
  51. 51. order Man, this is magic. This is awesome. This is “chuchu beleza”.
  52. 52. item 3 item 1 item 2 .item1 { order: 2; } .item2 { order: 3; } .item3 { order: 1; }
  53. 53. 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.
  54. 54. item 2 item 3 .item2 { flex-grow: 2; } item 1
  55. 55. flex-shrink Define how much the item will shrink.
  56. 56. item 2 .item2 { flex-shrink: 2; } item 3item 1
  57. 57. flex-basis Define the width of elements. This is works like max-width.
  58. 58. item 1 item 2 item 3 .item { flex-basis: 100%; } item 1 .item { flex-basis: 100px; } item 2 item 3
  59. 59. flex Shorthand that make all the magic.
  60. 60. item 1 item 2 item 3 .item { flex: 1; } .item { flex-grow: 1; flex-shrink: 1; flex-basis: auto; }
  61. 61. DEMO
  62. 62. http://flexiejs.com
  63. 63. philipwalton.github.io/solved-by-flexbox
  64. 64. Goodbye! Let me know what you think! @diegoeis @tableless http://tableless.com.br http://medium.com/@diegoeis http://slideshare.net/diegoeis

×