-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
929 lines (703 loc) · 49 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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<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,33;0,500;1,300&display=swap" rel="stylesheet">
<link rel="shortcut icon" type="image/png" href="./favicon.png">
<title>Flexbox Interactive Guide</title>
</head>
<body>
<main class="page-wrap">
<div class="title">
<h1>Flexbox Interactive Guide</h1>
<p class="title-paragraph">This interactive guide is inspired on the <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">CSS-Tricks.com's guide to Flexbox</a>
and has been made with the sole purpose of practicing what I've learned there.
<p>
</div>
<article>
<p class="text">Flexbox is a flexible box layout. It gives us the power to create responsive layouts that can automatically arrange depending on the screen size.</p>
<p class="text">It is based on a model that follows two directions, the main axis, that goes from the left to right, and the cross axis that goes from the top to the bottom.</p>
<br>
<details>
<p class="text">Since flexbox is a whole module and not a single property, it involves a lot of things including its whole set of properties. Some of them are meant to be set on the container (parent element, known as “flex container”) whereas the others are meant to be set on the children (said “flex items”).</p>
<p class="text">If “regular” layout is based on both block and inline flow directions, the flex layout is based on “flex-flow directions”. Please have a look at this figure from the specification, explaining the main idea behind the flex layout.</p>
<summary style="font-weight: bold; font-size: large;">Flexbox Basic Axis Information</summary>
<div class="example">
<img src="./Flexbox-basic.svg" id="flex-basic" alt="Image showing main and cross axis for a flexbox container, as well as the main and cross size, start and end.">
</div>
<p>Having trouble looking at the image? <a href="https://css-tricks.com/wp-content/uploads/2018/11/00-basic-terminology.svg" style="color: rgb(47, 131, 131);">Click here to take a closer look</a></p>
</details>
<br>
<br>
<h1 style="text-align: center; font-size: 200%;">Properties for the Parent (flex container)</h1>
<p style=" font-weight:bold">Example:</p>
<p class="text">Here we see a flex container with 3 items inside of it.</p>
<div class="example" id="flex-container-example">
<div class="example-graphic-container">
<div class="color-example">
<p id="container-identifier"></p>
<p>Flex container</p>
<p id="item-identifier"></p>
<p>Flex item</p>
</div>
<div class="flex-example">
<div class="flex-example-cross-axis">
<p class="axis-text">Cross Axis ↕</p>
</div>
<div class="flex-container">
<div class="flex-item-normal">1</div>
<div class="flex-item-normal">2</div>
<div class="flex-item-normal">3</div>
</div>
<div class="flex-example-invisible-cross-axis"> <!--This is only here for the sake of centering the graphic, forgive my soul i'm still learning-->
</div>
</div>
<div class="flex-example-main-axis">
<p class="axis-text">Main Axis ↔</p>
</div>
</div>
</div>
<br>
<p class="text">In order to define a flex container, we just need to add the property of "display: flex;" to the target's CSS:</p>
<div class="example">
<div class="code-container">
<p class="code-comment"><!-- html --></p>
<p class="code"><div <span class="code-class">class=</span><span class="code-string">"my-container"</span>></p>
<p class="code">ㅤㅤ<div><var>1</var></div></p>
<p class="code">ㅤㅤ<div><var>2</var></div></p>
<p class="code">ㅤㅤ<div><var>3</var></div></p>
<p class="code"></div></p>
</div>
<div class="code-container">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">display: <var>flex</var>; <span class="code-comment">/* or inline-flex */</span></p>
<p class="code">}</p>
</div>
</div>
<p class="text">And just like that, we have a flex container, which will inherit flex context for all of its direct children. </p>
<br><br>
<p style=" font-weight:bold">Flex Direction</p>
<p class="text">By default, whenever we define a flex container its direction will be set to "row", which has its main axis fit the items from left to right, and its cross axis from the top to the bottom.
However, we can change that with the "flex-direction" property:
</p>
<div class="example" id="flex-direction-example">
<div class="example-graphic-container">
<p class="example-title">Flex Direction</p>
<div class="flex-example">
<div class="flex-example-cross-axis" id="flex-direction-left-axis">
<p class="axis-text">Cross Axis ↕</p>
</div>
<div class="flex-container" id="flex-direction-container">
<div class="flex-item-normal">1</div>
<div class="flex-item-normal">2</div>
<div class="flex-item-normal">3</div>
</div>
<div class="flex-example-invisible-cross-axis"> <!--This is only here for the sake of centering the graphic, forgive my soul i'm still learning-->
</div>
</div>
<div class="flex-example-main-axis" id="flex-direction-bottom-axis">
<p class="axis-text">Main Axis ↔</p>
</div>
</div>
<div class="example-interactions" >
<p class="text">(You can click the buttons to change the property)</p>
<div class="example-buttons">
<div>
<button id="flex-direction-row-button">row (default)</button>
<button id="flex-direction-row-reverse-button">row-reverse</button>
</div>
<div>
<button id="flex-direction-column-button">column</button>
<button id="flex-direction-column-reverse-button">column-reverse</button>
</div>
</div>
<div class="code-container" id="code-container-flex-direction">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">flex-direction: <var>row</var>;</p>
<p class="code">}</p>
</div>
</div>
<p class="text">Although you may have already noticed, it's important to mention that by changing the "flex-direction" property to column or column-reverse,
the main axis and the cross axis will switch places, therefore the main axis will go from the top to the bottom, and the cross axis from left to right
(unless it's reversed, of course).
</p>
</div>
<br>
<br>
<p style=" font-weight:bold">Flex Wrap</p>
<p class="text">By default, flex items will try to fit onto one line. You can change that and allow the items to wrap as needed with the "flex-wrap" property.</p>
<p class="text">In this container, each flex item has the same size as in the previous example, however, since all of them are in the same line (or div) inside a
flex container, they shrink to fit into the container's size, this happens because the "flex-wrap" default property is "nowrap". As you can see, once
we change the flex-wrap property either to "wrap" or "wrap-reverse", the items turn back to their original size and move following the container's direction.
</p>
<div class="example" id="flex-wrap-example">
<div class="example-graphic-container">
<p class="example-title">Flex Wrap</p>
<div class="flex-example">
<div class="flex-container" id="flex-wrap-container">
<div class="flex-item-normal">1</div>
<div class="flex-item-normal">2</div>
<div class="flex-item-normal">3</div>
<div class="flex-item-normal">4</div>
<div class="flex-item-normal">5</div>
<div class="flex-item-normal">6</div>
<div class="flex-item-normal">7</div>
<div class="flex-item-normal">8</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="flex-wrap-wrap-button">wrap</button>
<button id="flex-wrap-nowrap-button">nowrap (default)</button>
<button id="flex-wrap-wrap-reverse-button">wrap-reverse</button>
</div>
</div>
<div class="code-container" id="code-container-flex-wrap">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">flex-wrap: <var>nowrap</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p>The flex-wrap properties are:</p>
<ul>
<li>nowrap (default): all flex items will be on one line</li>
<li>wrap: flex items will wrap onto multiple lines, from top to bottom.</li>
<li>wrap-reverse: flex items will wrap onto multiple lines from bottom to top.</li>
</ul>
<br><br>
<p style=" font-weight:bold">Flex Flow</p>
<p class="text">This is just a shorthand for the previous properties "flex-direction" and "flex-flow", it merges them so you can define both properties at once,
instead of doing it separately. Since flex-direction's default value is "row" and flex-wrap's is "nowrap", flex-flow follows the same convention, having
its default value set as "row nowrap".
</p>
<div class="example" id="flex-flow-example">
<div class="code-container">
<p class="code-comment">/* So instead of doing this */</p>
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">flex-direction: <var>column</var>; <span class="code-comment">/* or row/row-reverse/column-reverse */</span></p>
<p class="code">flex-wrap: <var>wrap</var>; <span class="code-comment">/* or wrap-reverse/nowrap */</span></p>
<p class="code">}</p>
</div>
<div class="code-container">
<p class="code-comment">/* You could do this */</p>
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">flex-flow: <var>column wrap</var>; <span class="code-comment">/* or whatever combination you want */</span></p>
<p class="code">}</p>
</div>
</div>
<p class="text">And that's about it, just a way to do more with less, pretty simple, right?</p>
<br><br>
<p style=" font-weight:bold">Justify Content</p>
<p class="text">This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are
inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.</p>
<div class="example" id="justify-content-example">
<div class="example-graphic-container">
<p class="example-title">Justify Content</p>
<div class="flex-example">
<div class="flex-container" style="width: 70%;" id="justify-content-container">
<div class="flex-item-normal-responsive">1</div>
<div class="flex-item-normal-responsive">2</div>
<div class="flex-item-normal-responsive">3</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="justify-content-flex-start-button">flex-start (default)</button>
<button id="justify-content-flex-end-button">flex-end</button>
<button id="justify-content-center-button">center</button>
</div>
<div>
<button id="justify-content-space-between-button">space-between</button>
<button id="justify-content-space-around-button">space-around</button>
<button id="justify-content-space-evenly-button">space-evenly</button>
</div>
</div>
<div class="code-container" id="code-container-justify-content">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">justify-content: <var>flex-start</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p>The justify-content properties are:</p>
<ul>
<li>flex-start (default): items are packed toward the start of the flex-direction.</li>
<li>flex-end: items are packed toward the end of the flex-direction.</li>
<li>center: items are centered along the line</li>
<li>space-between: items are evenly distributed in the line; first item is on the start line, last item on the end line</li>
<li>space-around: items are evenly distributed in the line with equal space around them. Note that visually the spaces aren't equal, since all the
items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the
next item because that next item has its own spacing that applies.</li>
<li>space-evenly: items are distributed so that the spacing between any two items (and the space to the edges) is equal.</li>
</ul>
<details>
<summary style="font-weight: bold;">Justify Content Extra Notes and Properties</summary>
<p>Some other properties for justify-content are:</p>
<ul>
<li>start: items are packed toward the start of the writing-mode direction.</li>
<li>end: items are packed toward the end of the writing-mode direction.</li>
<li>left: items are packed toward left edge of the container, unless that doesn't make sense with the flex-direction, then it behaves like start.</li>
<li>right: items are packed toward right edge of the container, unless that doesn’t make sense with the flex-direction, then it behaves like end.</li>
</ul>
<p class="text">Note that that browser support for these values is nuanced. For example, space-between never got support from some versions of Edge,
and start/end/left/right aren't in Chrome yet. MDN has detailed charts. The safest values are flex-start, flex-end, and center.</p>
<p class="text">There are also two additional keywords you can pair with these values: safe and unsafe. Using safe ensures that however you do this type
of positioning, you can't push an element such that it renders off-screen (e.g. off the top) in such a way the content can't be scrolled too
(called “data loss”).</p>
</details>
<br><br><br>
<p style=" font-weight:bold">Align Items</p>
<p class="text">This defines the default behavior for how flex items are laid out along the cross axis on the current line. Think of it as the justify-content version
for the cross-axis (perpendicular to the main-axis).</p>
<p class="text">In this case, I've added a red underline so you can spot the baseline easier and find the differences between the "baseline" and "center" properties.</p>
<br>
<div class="example" id="align-items-example">
<div class="example-graphic-container">
<p class="example-title">Align Items</p>
<div class="flex-example">
<div class="flex-container" style="height: 200px;" id="align-items-container">
<div class="flex-item-normal" style="height: auto; min-height: 60%; max-height: 100%; ">1</div>
<div class="flex-item-normal" style="height: auto; min-height: 75%; max-height: 100%; ">2</div>
<div class="flex-item-normal" style="height: auto; min-height: 25%; max-height: 100%; ">3</div>
<div class="flex-item-normal" style="height: auto; min-height: 45%; max-height: 100%; ">4</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="align-items-flex-start-button">flex-start</button>
<button id="align-items-flex-end-button">flex-end</button>
<button id="align-items-center-button">center</button>
</div>
<div>
<button id="align-items-stretch-button">stretch (default)</button>
<button id="align-items-baseline-button">baseline</button>
</div>
</div>
<div class="code-container" id="code-container-align-items">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">align-items: <var>stretch</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<br>
<p>The align-items properties are:</p>
<ul>
<li>stretch (default): stretch to fill the container (still respect min-width/max-width)</li>
<li>flex-start / start / self-start: items are placed at the start of the cross axis. The difference
between these is subtle, and is about respecting the flex-direction rules or the writing-mode rules.</li>
<li>flex-end / end / self-end: items are placed at the end of the cross axis. The difference again is subtle and
is about respecting flex-direction rules vs. writing-mode rules.</li>
<li>center: items are centered in the cross-axis</li>
<li>baseline: items are aligned such as their baselines align</li>
</ul>
<p class="text">The safe and unsafe modifier keywords can be used in conjunction with all the rest of these keywords (although note
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items" style="color: rgb(47, 131, 131)";>browser support</a>), and deal with helping you prevent aligning elements such that the content becomes inaccessible.
</p>
<br><br>
<p style=" font-weight:bold">Align Content</p>
<p class="text">The align-content property aligns a flex container's lines within when there is extra space in the cross-axis, similar to how justify-content aligns
individual items within the main-axis.
</p>
<p class="text"><span style="font-weight: bold; color: rgb(182, 46, 46);">Note:</span> This property only takes effect on multi-line flexible containers, where flex-wrap is set to either wrap or wrap-reverse). A single-line flexible
container (i.e. where flex-wrap is set to its default value, no-wrap) will not reflect align-content.
</p>
<div class="example" id="align-content-example">
<div class="example-graphic-container">
<p class="example-title">Align Content</p>
<div class="flex-example">
<div class="flex-container" style="height: 250px; flex-wrap: wrap; align-content: flex-start;" id="align-content-container">
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 25%;">1</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 48%;">2</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 20%;">3</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 15%;">4</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 15%;">5</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 45%;">6</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 15%">7</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 25%;">8</div>
<div class="flex-item-normal" style="height: auto; min-height: 20%; max-height: 33%; width: 25%;">9</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="align-content-flex-start-button">flex-start</button>
<button id="align-content-flex-end-button">flex-end</button>
<button id="align-content-center-button">center</button>
</div>
<div>
<button id="align-content-stretch-button">stretch</button>
<button id="align-content-space-between-button">space-between</button>
<button id="align-content-space-around-button">space-around</button>
</div>
</div>
<div class="code-container" id="code-container-align-content">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">flex-wrap: <var>wrap</var>;</p>
<p class="code">align-content: <var>flex-start</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<br>
<p>The align-content properties are:</p>
<ul>
<li>normal (default): items are packed in their default position as if no value was set.</li>
<li>flex-start / start: items packed to the start of the container. The (more supported) flex-start
honors the flex-direction while start honors the writing-mode direction.</li>
<li>flex-end / end: items packed to the end of the container. The (more support) flex-end honors the flex-direction while end honors the writing-mode
direction.</li>
<li>center: items centered in the container</li>
<li>space-between: items evenly distributed; the first line is at the start of the container while the last one is at the end</li>
<li>space-around: items evenly distributed with equal space around each line</li>
<li>space-evenly: items are evenly distributed with equal space around them</li>
<li>stretch: lines stretch to take up the remaining space</li>
</ul>
<p class="text">The safe and unsafe modifier keywords can be used in conjunction with all the rest of these keywords (although note browser support), and deal with
helping you prevent aligning elements such that the content becomes inaccessible.</p>
<br><br>
<p style=" font-weight:bold">Gap, Row Gap and Column Gap</p>
<p class="text">The gap property explicitly controls the space between flex items. It applies that spacing only between items not on the outer edges.</p>
<p class="text">There are many ways in which you can define the gap properties:</p>
<div class="example" id="gap-example">
<div class="code-container">
<p class="code-comment">/* gap */</p>
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">gap: <var>10px</var>; <span class="code-comment">/* When written like this, you are defining both the row and column gap */</span></p>
<p class="code">gap: <var>10px 20px</var>; <span class="code-comment">/* Or you can define them separately, the first value for the row and the second for the column */</span></p>
<p class="code">}</p>
</div>
<div class="code-container">
<p class="code-comment">/* row-gap, column-gap */</p>
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">row-gap: <var>10px</var>; <span class="code-comment">/* You can also define the properties like this */</span></p>
<p class="code">column-gap: <var>20px</var>; <span class="code-comment">/* in case you prefer being more specific */</span></p>
<p class="code">}</p>
</div>
</div>
<p class="text">And here we see a container with some flex items, you can try increasing/decreasing the gaps to see how they look.</p>
<div class="example" id="gap-example">
<div class="example-graphic-container">
<p class="example-title">Gap, Row Gap and Column Gap</p>
<div class="flex-example">
<div class="flex-container" style="flex-wrap: wrap; gap: 1px 2px;" id="gap-container">
<div class="flex-item-double">1</div>
<div class="flex-item-normal">2</div>
<div class="flex-item-double">3</div>
<div class="flex-item-double">4</div>
<div class="flex-item-normal">5</div>
<div class="flex-item-double">6</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons" style="display: flex; justify-content: space-evenly;">
<div style="display: flex; flex-direction: row; align-items: center;">
<p>row-gap:</p>
<button id="row-gap-minus-button" style="margin-left: 15px;">-</button>
<button id="row-gap-plus-button">+</button>
</div>
<div style="display: flex; flex-direction: row; align-items: center;">
<p style="width: 40%;">column-gap:</p>
<button id="column-gap-minus-button" style="margin-left: 15px;">-</button>
<button id="column-gap-plus-button">+</button>
</div>
</div>
<div class="code-container" id="code-container-align-content">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">row-gap: <var id="gap-row-var1">2</var>px;</p>
<p class="code">column-gap: <var id="gap-col-var1">2</var>px;</p>
<p class="code"><span class="code-comment">/* Or */</span></p>
<p class="code">gap: <var id="gap-row-var2">2</var>px <var id="gap-col-var2">2</var>px;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p class="text">The behavior could be thought of as a minimum gutter, as if the gutter is bigger somehow (because of something like justify-content: space-between;)
then the gap will only take effect if that space would end up smaller.
It is not exclusively for flexbox, gap works in grid and multi-column layout as well.
</p>
<p class="text">And that pretty much sums up the basics of what you should know about flex containers. There are, however, some other properties that you should know
about, and these are the ones meant for the children or flex items, let's get into them.
</p>
<br><br><br>
<h1 style="text-align: center; font-size: 200%;">Properties for the Children (flex items)</h1>
<br><br><br>
<p class="text">The following properties belong to the flex items, which means that they will apply to the children, and not to the parent/flex container.</p>
<br><br>
<p style=" font-weight:bold">Order</p>
<p class="text">By default, flex items are laid out in the source order. However, the order property controls the order in which they
appear in the flex container.
</p>
<p class="text">For this example, I have created a container with 4 flex items inside of it. There are 3 common items and another one that has
been colored green to make it easier to spot, I've called it "the dude". Each flex item has its "order" value set as 0, which is the
default value, therefore, the items will be placed as defined inside the container.
</p>
<div class="example">
<div class="code-container">
<p class="code-comment"><!-- html --></p>
<p class="code"><div <span class="code-class">class=</span><span class="code-string">"my-container"</span>></p>
<p class="code">ㅤㅤ<div><var>1</var></div></p>
<p class="code">ㅤㅤ<div <span class="code-class">id=</span><span class="code-string">"the-dude"</span>><var>The dude</var></div></p>
<p class="code">ㅤㅤ<div><var>3</var></div></p>
<p class="code">ㅤㅤ<div><var>3</var></div></p>
<p class="code"></div></p>
</div>
<div class="code-container">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>#the-dude</var> {</p>
<p class="code">order: <var>0</var>; <span class="code-comment">/* The default value is always 0 for the order property */</span></p>
<p class="code">}</p>
</div>
</div>
<p class="text">But what happens if we change the dude's order property?</p>
<div class="example" id="order-example">
<div class="example-graphic-container">
<p class="example-title">Order</p>
<div class="flex-example">
<div class="flex-container" id="order-container">
<div class="flex-item-normal">1</div>
<div class="flex-item-normal-dude" id="order-dude">The dude</div>
<div class="flex-item-normal">3</div>
<div class="flex-item-normal">4</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="order-zero-button">order: 0</button>
</div>
<div>
<button id="order-one-button">order: 1</button>
</div>
</div>
<div class="code-container" id="code-container-order">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>#the-dude</var> {</p>
<p class="code">order: <var>0</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p class="text">In this case, since the rest of the items have their order value set as 0 by default, the dude gets placed
last in the container, because its value is bigger than the rest. When we select the "0" value, it gets
back to its place since items with the same order value revert to their source order.
</p>
<br><br><br>
<p style=" font-weight:bold">Flex Grow</p>
<p class="text">This defines the ability for a flex item to grow if necessary. It accepts a unitless value that serves as a proportion.
It dictates what amount of the available space inside the flex container the item should take up.
</p>
<p class="text">If all items have flex-grow set to 1, the remaining space in the container will be distributed equally to all children.
If one of the children has a value of 2, that child would take up twice as much of the space either one of the others
(or it will try, at least).
</p>
<div class="example" id="flex-grow-example">
<div class="example-graphic-container">
<p class="example-title">Flex Grow</p>
<div class="flex-example">
<div class="flex-container" id="flex-grow-container">
<div class="flex-item-normal" style="width: auto; flex-grow: 1;">1</div>
<div class="flex-item-normal-dude" style="width: auto; flex-grow: 1" id="flex-grow-dude">2</div>
<div class="flex-item-normal" style="width: auto; flex-grow: 1">3</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="flex-grow-minus-button">Flex grow -</button>
</div>
<div>
<button id="flex-grow-plus-button">Flex grow +</button>
</div>
</div>
<div class="code-container" id="code-container-flex-grow">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>#the-dude</var> {</p>
<p class="code">width: <var>auto</var>;</p>
<p class="code">flex-grow: <var id="flex-grow-var">1</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p class="text"><span style="font-weight: bold; color: rgb(182, 46, 46);">Note:</span> Negative numbers are invalid.</p>
<br><br><br>
<p style=" font-weight:bold">Flex Shrink</p>
<p class="text">This defines the ability for a flex item to shrink if necessary.</p>
<p class="text">In this case you can see that each item has a width of 200px (set with flex basis), and when we modify the
container's width, the item with the most flex-shrink (The green item, the dude) is the one that shrinks the most.
You can modify the container's width with the buttons over the code container.
</p>
<p class="text">Negative numbers are also invalid with this one.</p>
<div class="example" id="flex-shrink-example">
<div class="example-graphic-container">
<p class="example-title">Flex Shrink</p>
<div class="flex-example">
<div class="flex-container" id="flex-shrink-container">
<div class="flex-shrink-item">1</div>
<div class="flex-shrink-item" style="color: white; background-color:rgb(14, 99, 32);
box-shadow: inset 10px 10px rgb(17, 126, 41); flex-shrink: 2;">2</div>
<div class="flex-shrink-item">3</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="flex-shrink-20-button">20%</button>
<button id="flex-shrink-60-button">60%</button>
</div>
<div>
<button id="flex-shrink-40-button">40%</button>
<button id="flex-shrink-80-button">80%</button>
</div>
</div>
<div class="code-container" id="code-container-flex-shrink">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>#The-dude</var> {</p>
<p class="code">flex-basis: <var>200px</var>;</p>
<p class="code">flex-shrink: <var>2</var>;</p>
<p class="code">}</p>
<p class="code"><var>.normal-flex-item</var> {</p>
<p class="code">flex-basis: <var>200px</var>;</p>
<p class="code">flex-shrink: <var>1</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p class="text">But, what is flex basis?</p>
<br><br><br>
<p style=" font-weight:bold">Flex Basis</p>
<p class="text">This defines the default size of an element before the remaining space is distributed. It can be a length
(e.g. 20%, 5rem, etc.) or a keyword. The auto keyword means “look at my width or height property” (which was temporarily
done by the main-size keyword until deprecated). The content keyword means “size it based on the item’s content” – this keyword
isn’t well supported yet, so it’s hard to test and harder to know what its brethren max-content, min-content, and fit-content do.
</p>
<br>
<div class="example">
<div class="code-container" id="code-container-flex-basis">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.flex-item</var> {</p>
<p class="code">flex-basis: <var>| auto</var>; <span class="code-comment">/* default auto */</span></p>
<p class="code">}</p>
</div>
</div>
<p class="text">If set to 0, the extra space around content isn’t factored in. If set to auto, the extra space is distributed based
on its flex-grow value. <a href="https://www.w3.org/TR/css-flexbox-1/images/rel-vs-abs-flex.svg" style="color: rgb(47, 131, 131)">See this graphic.</a>
</p>
<br><br><br>
<p style=" font-weight:bold">Flex</p>
<p class="text">
This is the shorthand for flex-grow, flex-shrink and flex-basis combined. The second and third parameters (flex-shrink
and flex-basis) are optional. The default is 0 1 auto, but if you set it with a single number value, like flex: 5;, that
changes the flex-basis to 0%, so it’s like setting flex-grow: 5; flex-shrink: 1; flex-basis: 0%;.
</p>
<br><br>
<div class="example">
<div class="code-container" id="code-container-flex-basis">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.flex-item</var> {</p>
<p class="code">flex: <var>0 1 auto</var>; <span class="code-comment">/* default values for flex-grow, flex-shrink and
flex-basis */</span></p>
<p class="code">}</p>
</div>
</div>
<p class="text">It is recommended that you use this shorthand property rather than set the individual properties. The shorthand sets
the other values intelligently.
</p>
<br><br><br>
<p style=" font-weight:bold">Align Self</p>
<p class="text">This allows the default alignment (or the one specified by align-items) to be overridden for individual flex items.</p>
<p class="text">Please see the align-items explanation to understand the available values.</p>
<br><br>
<div class="example" id="align-self-example">
<div class="example-graphic-container">
<p class="example-title">Align Self</p>
<div class="flex-example">
<div class="flex-container" style="height: 200px; width: 60%; align-items: center; justify-content: space-evenly;" id="align-self-container">
<div class="flex-item-normal" style="height: auto; min-height: 60%; max-height: 100%; ">1</div>
<div class="flex-item-normal" style="height: auto; min-height: 75%; max-height: 100%; ">2</div>
<div class="flex-item-normal" style="height: auto; min-height: 25%; max-height: 100%; ">3</div>
<div class="flex-item-normal" style="height: auto; min-height: 45%; max-height: 100%; ">4</div>
<div class="flex-item-normal-dude" id="align-self-dude" style="height: auto; min-height: 25%; max-height: 100%;">5</div>
</div>
</div>
<br><br>
</div>
<div class="example-interactions" >
<div class="example-buttons">
<div>
<button id="align-self-flex-start-button">flex-start</button>
<button id="align-self-flex-end-button">flex-end</button>
<button id="align-self-center-button">center</button>
</div>
<div>
<button id="align-self-stretch-button">stretch (default)</button>
<button id="align-self-baseline-button">baseline</button>
</div>
</div>
<div class="code-container" id="code-container-align-self">
<p class="code-comment">/* CSS */</p>
<p class="code"><var>.my-container</var> {</p>
<p class="code">align-items: <var>center</var>;</p>
<p class="code">}</p>
<p class="code"><var>#The-dude</var> {</p>
<p class="code">align-self: <var>center</var>;</p>
<p class="code">}</p>
</div>
</div>
</div>
<p class="text">Note that float, clear and vertical-align have no effect on a flex item.</p>
<br><br><br>
<p class="text">And those are the basics of flexbox. Even though I didn't cover all of the flexbox's magic tricks in this guide,
there's a lot you can already do with what you've seen here, it's all practice from this point.
It may take you some time to get a good grasp of all the concepts, but I hope
that this can help you at least a little in your journey, good luck!.
</p>
<br>
</article>
<p class="text" style="text-align: center; color: white;">Special thanks to Chris Coyier and the people at CSS Tricks for having an awesome guide in which I heavily relied to write this.</p>
<div class="example" style="justify-content: center;">
<a href="https://github.com/OneNakedBass"><img id="github-photo" src="https://avatars.githubusercontent.com/u/71959291?v=4" alt="Martin Bracamonte's Github profile picture"></a>
<a href="https://github.com/OneNakedBass" style="color:white;"><p style="font-weight:bold">Find me on Github!</p></a>
</div>
<br><br><br>
</main>
<br><br>
</body>
<script src="./script.js"></script>
</html>