FLEXBOX
1
FLEXBOX 1 CHRIS SAUVE 2 LAYOUT STRATEGIES 3 TABLES 4 JUST - - PowerPoint PPT Presentation
FLEXBOX 1 CHRIS SAUVE 2 LAYOUT STRATEGIES 3 TABLES 4 JUST DONT. 5 ABSOLUTE POSITIONING 6 INLINE BLOCK 7 FLOATS 8 THINK DIFFERENT 9 CONTENT-OUT LAYOUT 10 parent child child child 1 2 3 11 parent child child
1
2
3
4
5
6
7
8
9
10
parent child
child
child
11
parent child
child
child
12
parent child
child
child
13
14
YES YES YES 10+ only
YES
even ¡in ¡Mini!
15
YES YES YES 10+ only
YES
even ¡in ¡Mini!
16
17
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column
18
flex-‑direction: ¡row;
19
flex-‑direction: ¡column;
20
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column
21
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column align-‑items: ¡stretch;
22
Cross Axis
align-‑items
23
align-‑items: ¡stretch; ¡// ¡default
24
align-‑items: ¡center;
25
align-‑items: ¡flex-‑start;
26
align-‑items: ¡flex-‑end;
27
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column align-‑items: ¡stretch;
28
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column align-‑items: ¡stretch; justify-‑content: ¡center;
29
Main Axis
justify-‑content
30
justify-‑content: ¡center;
31
justify-‑content: ¡flex-‑start;
32
justify-‑content: ¡flex-‑end;
33
justify-‑content: ¡space-‑between;
34
justify-‑content: ¡space-‑around;
35
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column align-‑items: ¡stretch; justify-‑content: ¡center;
36
display: ¡flex; ¡// ¡or ¡inline-‑flex flex-‑direction: ¡row; ¡// ¡or ¡column align-‑items: ¡stretch; justify-‑content: ¡center; flex-‑wrap: ¡nowrap;
37
flex-‑wrap: ¡nowrap;
38
flex-‑wrap: ¡wrap;
39
40
flex-‑grow: ¡0; flex-‑shrink: ¡0; flex-‑basis: ¡auto;
41
flex-‑basis: ¡<number>; flex-‑basis: ¡auto; width: ¡<number>;
42
100px 20px 20px 20px
43
100px 20px 20px 20px
44
flex-‑grow: ¡0; flex-‑grow: ¡0; flex-‑grow: ¡0; 45
flex-‑grow: ¡1;
13px of growth
flex-‑grow: ¡1;
13px of growth
flex-‑grow: ¡1;
13px of growth
46
flex-‑grow: ¡1;
10px of growth
flex-‑grow: ¡2;
20px of growth
flex-‑grow: ¡1;
10px of growth
47
flex-‑grow: ¡0;
0px of growth
flex-‑grow: ¡1;
20px of growth
flex-‑grow: ¡1;
20px of growth
48
40px 20px 20px 20px
49
40px 20px 20px 20px
50
flex-‑shrink: ¡0; flex-‑shrink: ¡0; flex-‑shrink: ¡0;
51
flex-‑shrink: ¡0; flex-‑shrink: ¡1; flex-‑shrink: ¡1;
0px of shrink 10px of shrink 10px of shrink
52
53
54
55
codepen.io/lemonmade/pen/RNEpJR?editors=110
56
57
Header Content
Sidebar
Footer
58 <div ¡class="page"> ¡ ¡ ¡<header ¡class="page__header">Header</header> ¡ ¡ ¡<div ¡class="page__content"> ¡ ¡ ¡ ¡ ¡<aside ¡class="page__sidebar">Sidebar</aside> ¡ ¡ ¡ ¡ ¡<main ¡class="page__main">Content</section> ¡ ¡ ¡</div> ¡ ¡ ¡<footer ¡class="page__footer">Footer</footer> ¡ </div> ¡
59
Header Content Sidebar Footer
60
.page ¡{ ¡ ¡ ¡min-‑height: ¡100vh; ¡ ¡ ¡display: ¡flex; ¡ ¡ ¡flex-‑direction: ¡column; ¡ } ¡ .page__header, ¡ .page__footer ¡{ ¡ ¡ ¡flex: ¡0 ¡0 ¡auto; ¡// ¡default, ¡so ¡you ¡can ¡just ¡exclude ¡ } ¡ .page__content ¡{ ¡ ¡ ¡flex: ¡1 ¡0 ¡auto; ¡ } ¡
61
Header Content Sidebar Footer
62
.page__content ¡{ ¡ ¡ ¡display: ¡flex; ¡ } ¡ .page__sidebar ¡{ ¡ ¡ ¡flex: ¡0 ¡0 ¡auto; ¡// ¡again, ¡default, ¡so ¡safe ¡to ¡exclude ¡ } ¡ .page__main ¡{ ¡ ¡ ¡flex: ¡1 ¡1 ¡auto; ¡ } ¡
63
Header Content Sidebar Footer
64 @media ¡screen ¡and ¡(max-‑width: ¡30rem) ¡{ ¡ ¡ ¡.page__content ¡{ ¡ ¡ ¡ ¡ ¡flex-‑direction: ¡column; ¡ ¡ ¡} ¡ } ¡
65
Header Content Sidebar Footer
66
codepen.io/lemonmade/pen/XJobem?editors=110
67
68 <div ¡class="popover"> ¡ ¡ ¡<div ¡class="popover__content"> ¡ ¡ ¡ ¡ ¡<div ¡class="popover__pane ¡popover__pane-‑-‑ fixed">Don't ¡hide ¡this ¡one!</div> ¡ ¡ ¡ ¡ ¡<div ¡class="popover__pane"> ¡ ¡ ¡ ¡ ¡ ¡ ¡<p>Feel ¡free ¡to ¡scroll ¡this.</p> ¡ ¡ ¡ ¡ ¡</div> ¡ ¡ ¡</div> ¡ </div> ¡
69
70
71
JavaScript says:
Please Stop Here
72 .popover ¡{ ¡ ¡ ¡display: ¡flex; ¡ } ¡
73
74 .popover__content ¡{ ¡ ¡ ¡display: ¡flex; ¡ ¡ ¡flex-‑direction: ¡column; ¡ } ¡ .popover__pane ¡{ ¡ ¡ ¡flex: ¡1 ¡1 ¡auto; ¡ ¡ ¡overflow: ¡auto; ¡ } ¡ .popover__pane-‑-‑fixed ¡{ ¡ ¡ ¡flex: ¡0 ¡0 ¡auto; ¡ } ¡
75
76
77
78
codepen.io/lemonmade/pen/GgPJEx?editors=110
79
<div ¡class="button__container"> ¡ ¡ ¡<button ¡class="button">Button ¡the ¡first</button> ¡ ¡ ¡<button ¡class="button">Button ¡the ¡second, ¡ junior</button> ¡ </div> ¡ <p ¡class="type ¡type-‑-‑paragraph">Lorem ¡ipsum ¡dolor ¡ sit ¡amet...</p> ¡
80
81
$default-‑spacing: ¡1rem; ¡ .button-‑container ¡{ ¡ ¡ ¡display: ¡flex; ¡ ¡ ¡margin-‑right: ¡(-‑1 ¡* ¡$default-‑spacing); ¡ ¡ ¡margin-‑bottom: ¡(-‑1 ¡* ¡$default-‑spacing); ¡ } ¡ .button ¡{ ¡ ¡ ¡margin: ¡0 ¡$default-‑spacing ¡$default-‑spacing ¡0; ¡ } ¡
82
83
.button ¡{ ¡ ¡ ¡flex: ¡1 ¡1 ¡0px; ¡ } ¡
84
85
86
@media ¡screen ¡and ¡(max-‑width: ¡$some-‑magic-‑number) ¡{ ¡ ¡ ¡.button-‑container ¡{ ¡ ¡ ¡ ¡ ¡display: ¡block; ¡ ¡ ¡} ¡ ¡ ¡.button ¡{ ¡ ¡ ¡ ¡ ¡width: ¡100%; ¡ ¡ ¡} ¡ } ¡
87
.button-‑container ¡{ ¡ ¡ ¡flex-‑wrap: ¡wrap; ¡ } ¡ .button ¡{ ¡ ¡ ¡flex: ¡1 ¡0 ¡auto; ¡ }
88
89
.button-‑container ¡{ ¡ ¡ ¡flex-‑wrap: ¡wrap; ¡ } ¡ .button ¡{ ¡ ¡ ¡flex: ¡1 ¡0 ¡0px; ¡ ¡ ¡min-‑width: ¡min-‑content; ¡ } ¡
90
91
codepen.io/lemonmade/pen/ZYgNmy?editors=110
92
(something like…)
93 <div ¡class="card"> ¡ ¡ ¡<header ¡class="card__section ¡card__section-‑-‑ header"> ¡ ¡ ¡ ¡ ¡ ¡<h1 ¡class=“heading">Medium ¡Heading</h1> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<div ¡class="button-‑group"> ¡ ¡ ¡ ¡ ¡ ¡ ¡<div ¡class="button-‑group__primary"> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<button ¡class="button ¡button-‑-‑ primary">Primary ¡Action</button> ¡ ¡ ¡ ¡ ¡ ¡ ¡</div> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<div ¡class="button-‑group__secondary"> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<button ¡class="button">Action ¡1</button> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<button ¡class="button">Action ¡2</button> ¡ ¡ ¡ ¡ ¡ ¡ ¡</div> ¡ ¡ ¡ ¡ ¡</div> ¡ ¡ ¡</header> ¡ </div> ¡
94
95
.card__section-‑-‑header ¡{ ¡ ¡ ¡display: ¡flex; ¡ ¡ ¡align-‑items: ¡center; ¡ } ¡ .heading ¡{ ¡ ¡ ¡flex: ¡1 ¡0 ¡auto; ¡ } ¡ .button-‑group ¡{ ¡ ¡ ¡flex: ¡0 ¡0 ¡auto; ¡ }
96
97
.button-‑group ¡{ ¡ ¡ ¡display: ¡inline-‑flex; ¡ ¡ ¡flex-‑direction: ¡row-‑reverse; ¡ } ¡ .button-‑group__primary, ¡ .button-‑group__secondary ¡{ ¡ ¡ ¡display: ¡flex; ¡ }
98
99
100
.card__section-‑-‑header ¡{ ¡ ¡ ¡flex-‑wrap: ¡wrap; ¡ }
101
102
.button-‑group ¡{ ¡ ¡ ¡flex: ¡0.0001 ¡0 ¡auto; ¡ } ¡ .heading ¡{ ¡ ¡ ¡flex: ¡1000 ¡0 ¡auto; ¡ } ¡ .button-‑group__secondary ¡{ ¡ ¡ ¡flex: ¡1 ¡0 ¡auto; ¡ }
103
104
.button-‑group ¡{ ¡ ¡ ¡max-‑width: ¡100%; ¡ ¡ ¡flex-‑wrap: ¡wrap-‑reverse; ¡ } ¡ .button-‑group__primary ¡{ ¡ ¡ ¡flex: ¡0.0001 ¡0 ¡auto; ¡ } ¡ .button-‑group__secondary ¡{ ¡ ¡ ¡max-‑width: ¡100%; ¡ ¡ ¡flex: ¡1000 ¡0 ¡auto; ¡ ¡ ¡flex-‑wrap: ¡wrap; ¡ }
105
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
106
https://github.com/postcss/autoprefixer
107
https://github.com/philipwalton/flexbugs
108
109
110
111