-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
576 lines (522 loc) · 24.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>Flexbox Cheat Sheet</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
<style>
body {
background: linear-gradient(120deg, hsl(0, 0%, 8%) 0%, hsl(0, 0%, 10%) 100%);
color: hsl(0, 0%, 48%);
margin: 40px;
display: flex;
justify-content: center;
font-family: "Roboto", Arial, Helvetica, sans-serif;
font-size: 10.5pt;
line-height: 1.5em;
}
a {
color: hsl(280, 20%, 65%);
text-decoration: none;
}
a:hover {
color: hsl(280, 40%, 80%);
text-decoration: underline;
}
main {
columns: 2;
}
header {
padding: 0 20px 0 20px;
max-width: 260px;
}
header h1 {
margin: 0.2em 0 0.6em;
font-size: 56pt;
font-weight: 900;
line-height: 0.85em;
color: hsl(280, 70%, 40%);
}
header h1 span {
color: hsl(280, 70%, 30%);
}
header h1 span + span {
color: hsl(280, 70%, 20%);
}
article {
display: block;
break-inside: avoid-column;
max-width: 660px;
margin: 0 20px 40px;
padding: 35px;
border: 1px dashed hsl(200, 0%, 30%);
}
_:-ms-fullscreen, :root article { /* IE11 hack */
width: 640px;
}
article h1 {
margin: 0;
font-weight: 500;
color: hsla(210, 0%, 80%, 1);
}
article h1 small {
font-weight: 400;
font-size: 8pt;
vertical-align: 8pt;
padding: 3px;
color: hsla(180, 70%, 45%, 1);
}
article p {
font-size: 12pt;
line-height: 1.35em;
font-size: 10.5pt;
line-height: 1.5em;
}
section.examples {
display: flex;
flex-wrap: wrap;
justify-content: start;
}
section.example {
position: relative;
margin: 20px 40px 0 0;
display: flex;
flex-direction: column;
align-items: start;
}
section.example h2 {
margin: 0 0 5px 2px;
font-size: 10.5pt;
font-weight: 400;
letter-spacing: 0.5px;
color: hsla(210, 0%, 80%, 1);
user-select: all;
}
div.flex-container {
background: hsl(280, 70%, 12%);
background: radial-gradient(circle, hsl(280, 70%, 20%) 0%, hsl(280, 70%, 12%) 100%);
border: 3px groove hsl(280, 70%, 40%);
border-radius: 10px;
box-shadow: 4px 4px 8px hsl(280, 40%, 8%);
width: 270px;
height: 100px;
display: flex;
}
div.flex-item {
background: hsla(50, 100%, 50%, 1);
color: hsla(50, 100%, 35%, 1);
border: 2px outset hsla(50, 100%, 40%, 1);
border-radius: 7px;
box-shadow: 1px 1px 1px hsl(320, 70%, 8%);
font-weight: 900;
padding: 10px;
}
div.flex-item:nth-child(1) { font-size: 16pt; }
div.flex-item:nth-child(2) { font-size: 24pt; }
div.flex-item:nth-child(3) { font-size: 14pt; }
div.flex-item:nth-child(4) { font-size: 36pt; }
div.flex-item:nth-child(5) { font-size: 18pt; }
div.flex-item:nth-child(6) { font-size: 12pt; }
div.flex-item:nth-child(7) { font-size: 32pt; }
div.flex-item:nth-child(8) { font-size: 24pt; }
div.flex-item:nth-child(9) { font-size: 18pt; }
div.flex-item:nth-child(10) { font-size: 12pt; }
div.flex-item:nth-child(11) { font-size: 32pt; }
div.flex-item:nth-child(12) { font-size: 24pt; }
article.flex-direction section.example:nth-child(3) div.flex-container,
article.flex-direction section.example:nth-child(4) div.flex-container {
width: 170px;
height: 250px;
}
article.flex-wrap section.example:nth-child(1) {
width: 50%;
}
article.order div.flex-item:nth-child(3) {
background: hsla(180, 70%, 50%, 1);
color: hsla(180, 70%, 35%, 1);
border: 2px outset hsla(180, 70%, 40%, 1);
}
article.flex-grow div.flex-item {
background: hsla(180, 70%, 50%, 1);
color: hsla(180, 70%, 35%, 1);
border: 2px outset hsla(180, 70%, 40%, 1);
}
article.align-self div.flex-item:nth-child(3) {
background: hsla(180, 70%, 50%, 1);
color: hsla(180, 70%, 35%, 1);
border: 2px outset hsla(180, 70%, 40%, 1);
}
article.align-content div.flex-container{
flex-wrap: wrap;
height: 200px;
}
@media screen and (max-width: 1270px) {
main {
columns: auto;
}
}
@media screen and (max-width: 790px) {
body {
flex-direction: column;
}
header {
max-width: 100%;
}
article {
margin: 30px 0;
}
}
@media screen and (max-width: 480px) {
body {
margin: 5px 25px;
}
header {
padding: 0;
max-width: auto;
}
header h1 {
margin: 0.2em 0 0.4em 0;
font-size: 40pt;
}
article {
margin: 10px 0;
padding: 14px;
}
}
</style>
</head>
<body>
<header>
<h1>Flexbox <span>Cheat</span> <span>Sheet</span></h1>
<p>This cheat sheet is done entirely in HTML and CSS, which means you may see some differences in rendering, depending on which browser you use (especially if you use an old browser like Internet Explorer 11). This is done on purpose – here you can check in details how flexbox works in different browsers (or how it doesn't work). However, rememeber that <strong>whatever you SEE on this page may be incorrect according to web standards</strong>, because browsers have bugs – but the code is correct.</p>
<p>In the examples the violet elements are <em>flex containers</em> and the golden elements are <em>flex items</em>.</p>
<p>The descriptions of the properties come <a href="https://www.w3.org/TR/css-flexbox-1/">from the W3C specification</a>.</p>
<p>🢂 <a href="https://github.com/thesigns/FlexboxCheatSheet">GitHub page of the project</a></p>
<p>Version 0.2</p>
</header>
<main>
<!------------------------ flex-direction ------------------------>
<article class="flex-direction">
<h1>flex-direction</h1>
<p>The flex-direction property specifies how flex items are placed in the flex container, by setting the direction of the flex container’s main axis. This determines the direction in which flex items are laid out.</p>
<section class="examples">
<section class="example">
<h2>flex-direction: row</h2>
<div class="flex-container" style="flex-direction: row ">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>flex-direction: row-reverse</h2>
<div class="flex-container" style="flex-direction: row-reverse">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>flex-direction: column</h2>
<div class="flex-container" style="flex-direction: column">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>flex-direction: column-reverse</h2>
<div class="flex-container" style="flex-direction: column-reverse">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
</section>
</article>
<!------------------------ flex-wrap ------------------------>
<article class="flex-wrap">
<h1>flex-wrap</h1>
<p>The flex-wrap property controls whether the flex container is single-line or multi-line, and the direction of the cross-axis, which determines the direction new lines are stacked in.</p>
<section class="examples">
<section class="example">
<h2>flex-wrap: nowrap</h2>
<div class="flex-container" style="flex-wrap: nowrap ">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
</div>
</section>
<section class="example">
<h2>flex-wrap: wrap</h2>
<div class="flex-container" style="flex-wrap: wrap">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
</div>
</section>
<section class="example">
<h2>flex-wrap: wrap-reverse</h2>
<div class="flex-container" style="flex-wrap: wrap-reverse">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
</div>
</section>
</section>
</article>
<!------------------------ flex-flow ------------------------>
<article class="flex-flow">
<h1>flex-flow</h1>
<p>The flex-flow property is a shorthand for setting the flex-direction and flex-wrap properties, which together define the flex container's main and cross axes.</p>
<section class="examples">
<section class="example">
<h2>flex-flow: column wrap</h2>
<div class="flex-container" style="flex-flow: column wrap">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
</div>
</section>
<section class="example">
<h2>flex-flow: column wrap-reverse</h2>
<div class="flex-container" style="flex-flow: column wrap-reverse">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
</div>
</section>
</section>
</article>
<!------------------------ order ------------------------>
<article class="order">
<h1>order <small>(flex item property)</small></h1>
<p>The order property controls the order in which flex items appear within the flex container, by assigning them to ordinal groups. It takes a single integer value, which specifies which ordinal group the flex item belongs to. The default value is 0.</p>
<section class="examples">
<section class="example">
<h2>order: -1</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="order: -1">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div>
</div>
</section>
<section class="example">
<h2>order: 1</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="order: 1">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div>
</div>
</section>
</section>
</article>
<!------------------------ flex-grow ------------------------>
<article class="flex-grow">
<h1>flex <small>(flex item property)</small></h1>
<p>The defining aspect of flex layout is the ability to make the flex items "flex", altering their width/height to fill the available space in the main dimension. This is done with the flex property. A flex container distributes free space to its items (proportional to their flex grow factor) to fill the container, or shrinks them (proportional to their flex shrink factor) to prevent overflow.</p>
<p> A flex item is fully inflexible if both its flex-grow and flex-shrink values are zero, and flexible otherwise.</p>
<section class="examples">
<section class="example">
<h2>flex: 0 / flex: 0 / flex: 0</h2>
<div class="flex-container">
<div class="flex-item" style="flex: 0">1</div>
<div class="flex-item" style="flex: 0">2</div>
<div class="flex-item" style="flex: 0">3</div>
</div>
</section>
<section class="example">
<h2>flex: 0 / flex: 1 / flex: 0</h2>
<div class="flex-container">
<div class="flex-item" style="flex: 0">1</div>
<div class="flex-item" style="flex: 1">2</div>
<div class="flex-item" style="flex: 0">3</div>
</div>
</section>
<section class="example">
<h2>flex: 2 / flex: 0 / flex: 1</h2>
<div class="flex-container">
<div class="flex-item" style="flex: 2">1</div>
<div class="flex-item" style="flex: 0">2</div>
<div class="flex-item" style="flex: 1">3</div>
</div>
</section>
<section class="example">
<h2>flex: 1 / flex: 2 / flex: 4</h2>
<div class="flex-container">
<div class="flex-item" style="flex: 1">1</div>
<div class="flex-item" style="flex: 2">2</div>
<div class="flex-item" style="flex: 4">3</div>
</div>
</section>
</section>
</article>
<!------------------------ justify-content ------------------------>
<article class="justify-content">
<h1>justify-content</h1>
<p>The justify-content property aligns flex items along the main axis of the current line of the flex container. This is done after any flexible lengths and any auto margins have been resolved.</p>
<section class="examples">
<section class="example">
<h2>justify-content: flex-start</h2>
<div class="flex-container" style="justify-content: flex-start">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>justify-content: flex-end</h2>
<div class="flex-container" style="justify-content: flex-end">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>justify-content: center</h2>
<div class="flex-container" style="justify-content: center">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>justify-content: space-between</h2>
<div class="flex-container" style="justify-content: space-between">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>justify-content: space-around</h2>
<div class="flex-container" style="justify-content: space-around">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>justify-content: space-evenly</h2>
<div class="flex-container" style="justify-content: space-evenly">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
</section>
</article>
<!------------------------ align-items ------------------------>
<article class="align-items">
<h1>align-items</h1>
<p>Flex items can be aligned in the cross axis of the current line of the flex container, similar to justify-content but in the perpendicular direction. align-items sets the default alignment for all of the flex container's items, including anonymous flex items.</p>
<section class="examples">
<section class="example">
<h2>align-items: flex-start</h2>
<div class="flex-container" style="align-items: flex-start">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-items: flex-end</h2>
<div class="flex-container" style="align-items: flex-end">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-items: center</h2>
<div class="flex-container" style="align-items: center">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-items: baseline</h2>
<div class="flex-container" style="align-items: baseline">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-items: stretch</h2>
<div class="flex-container" style="align-items: stretch">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
</div>
</section>
</section>
</article>
<!------------------------ align-self ------------------------>
<article class="align-self">
<h1>align-self <small>(flex item property)</small></h1>
<p>Property align-self allows default alignment to be overridden for individual flex items (for anonymous flex items, align-self always matches the value of align-items on their associated flex container).</p>
<section class="examples">
<section class="example">
<h2>align-self: auto</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="align-self: auto">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-self: flex-start</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="align-self: flex-start">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-self: flex-end</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="align-self: flex-end">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-self: center</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="align-self: center">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-self: baseline</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="align-self: baseline">3</div><div class="flex-item">4</div>
</div>
</section>
<section class="example">
<h2>align-self: stretch</h2>
<div class="flex-container">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item" style="align-self: stretch">3</div><div class="flex-item">4</div>
</div>
</section>
</section>
</article>
<!------------------------ align-content ------------------------>
<article class="align-content">
<h1>align-content</h1>
<p>The align-content property aligns a flex container’s lines within the flex container when there is extra space in the cross-axis, similar to how justify-content aligns individual items within the main-axis. Note, this property has no effect on a single-line flex container.</p>
<section class="examples">
<section class="example">
<h2>align-content: flex-start</h2>
<div class="flex-container" style="align-content: flex-start">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
<div class="flex-item">9</div><div class="flex-item">10</div><div class="flex-item">11</div><div class="flex-item">12</div>
</div>
</section>
<section class="example">
<h2>align-content: flex-start</h2>
<div class="flex-container" style="align-content: flex-end">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
<div class="flex-item">9</div><div class="flex-item">10</div><div class="flex-item">11</div><div class="flex-item">12</div>
</div>
</section>
<section class="example">
<h2>align-content: center</h2>
<div class="flex-container" style="align-content: center">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
<div class="flex-item">9</div><div class="flex-item">10</div><div class="flex-item">11</div><div class="flex-item">12</div>
</div>
</section>
<section class="example">
<h2>align-content: space-between</h2>
<div class="flex-container" style="align-content: space-between">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
<div class="flex-item">9</div><div class="flex-item">10</div><div class="flex-item">11</div><div class="flex-item">12</div>
</div>
</section>
<section class="example">
<h2>align-content: space-around</h2>
<div class="flex-container" style="align-content: space-around">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
<div class="flex-item">9</div><div class="flex-item">10</div><div class="flex-item">11</div><div class="flex-item">12</div>
</div>
</section>
<section class="example">
<h2>align-content: stretch</h2>
<div class="flex-container" style="align-content: stretch">
<div class="flex-item">1</div><div class="flex-item">2</div><div class="flex-item">3</div><div class="flex-item">4</div>
<div class="flex-item">5</div><div class="flex-item">6</div><div class="flex-item">7</div><div class="flex-item">8</div>
<div class="flex-item">9</div><div class="flex-item">10</div><div class="flex-item">11</div><div class="flex-item">12</div>
</div>
</section>
</section>
</article>
</main>
</body>
</html>