generated from foambubble/foam-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexbox-classes.html
960 lines (806 loc) · 32.3 KB
/
flexbox-classes.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
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<html>
<head>
<style>
/* Flexbox helpers */
.hbox,
.vbox {
display: flex;
}
.hbox {
flex-direction: row;
}
.vbox {
flex-direction: column;
}
.hbox.reverse {
flex-direction: row-reverse;
}
.vbox.reverse {
flex-direction: column-reverse;
}
.hbox.inline,
.vbox.inline {
display: inline-flex;
}
.hbox.wrap,
.vbox.wrap {
flex-wrap: wrap;
}
.hbox.wrap-reverse,
.vbox.wrap-reverse {
flex-wrap: wrap-reverse;
}
/* Flexbox alignment */
.hbox.halign-items-start,
.vbox.valign-items-start {
justify-content: flex-start;
}
.hbox.halign-items-center,
.vbox.valign-items-center {
justify-content: center;
}
.hbox.halign-items-end,
.vbox.valign-items-end {
justify-content: flex-end;
}
/* Alignment in cross-axis. */
.hbox.valign-items-start,
.vbox.halign-items-start {
align-items: flex-start;
}
.hbox.valign-items-center,
.vbox.halign-items-center {
align-items: center;
}
.hbox.valign-items-end,
.vbox.halign-items-end {
align-items: flex-end;
}
/* Self/item alignment. */
.hbox > .valign-start,
.vbox > .halign-start,
.hbox.valign-items-start > *,
.vbox.halign-items-start > * {
align-self: flex-start;
}
.hbox > .valign-center,
.vbox > .halign-center,
.hbox.valign-items-center > *,
.vbox.halign-items-center > * {
align-self: center;
}
.hbox > .valign-end,
.vbox > .halign-end,
.hbox.valign-items-end > *,
.vbox.halign-items-end > * {
align-self: flex-end;
}
/* Stretch "alignment" */
.hbox > .hgrow, /* obsolete - use .halign-stretch */
.hbox > .halign-stretch,
.vbox > .valign-stretch,
.hbox.halign-items-stretch > *,
.vbox.valign-items-stretch > * {
flex-grow: 1;
}
.hbox > .halign-stretch-2,
.vbox > .valign-stretch-2 {
flex-grow: 2;
}
.hbox > .halign-stretch-3,
.vbox > .valign-stretch-3 {
flex-grow: 3;
}
.hbox.valign-items-stretch,
.vbox.halign-items-stretch {
align-items: stretch;
}
.hbox > .valign-stretch,
.vbox > .halign-stretch,
.hbox.valign-items-stretch > *,
.vbox.halign-items-stretch > * {
align-self: stretch;
}
/* Space distribution */
.hbox.halign-items-space-around,
.vbox.valign-items-space-around {
justify-content: space-around;
}
.hbox.valign-items-space-around,
.vbox.halign-items-space-around {
align-content: space-around;
}
.hbox.halign-items-space-between,
.vbox.valign-items-space-between {
justify-content: space-between;
}
.hbox.valign-items-space-between,
.vbox.halign-items-space-between {
align-content: space-between;
}
.hbox.halign-items-space-evenly,
.vbox.valign-items-space-evenly {
justify-content: space-evenly;
}
.hbox.valign-items-space-evenly,
.vbox.halign-items-space-evenly {
align-content: space-evenly;
}
.hbox > .spacer,
.hbox > .spacer-1,
.vbox > .spacer,
.vbox > .spacer-1 {
flex-grow: 1;
visibility: hidden;
}
.hbox > .spacer-2,
.vbox > .spacer-2 {
flex-grow: 2;
visibility: hidden;
}
.hbox > .spacer-3,
.vbox > .spacer-3 {
flex-grow: 3;
visibility: hidden;
}
`;
</style>
<style>
.general {
width: 100%;
}
.general>div {
background-color: #ccc;
padding: 4px;
margin: 12px;
}
body {
font-family: 'Roboto', 'Noto', sans-serif;
font-size: 14px;
margin: 0;
padding: 24px;
background-color: #fafafa;
}
.centered {
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
.container {
position: relative;
border: 1px solid #000;
background-color: #ccc;
padding: 0;
margin: 0;
}
.container div {
border: 1px solid #000;
border-radius: 3px;
padding: 5px;
margin: 0;
background-color: white;
min-height: 20px;
}
/* container with a label should add margin-top to the container */
.container:has(label) {
margin-top: 2.5em;
}
.container label {
position: absolute;
left: 1em;
top: -2em;
background: white;
border: 2px solid lightgray;
border-radius: 4px;
padding: 2px 4px;
white-space: nowrap;
overflow: visible;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px
}
/* Make spacers in containers slightly visible with a mostly transparent background pattern. */
.container>.spacer,
.container>.spacer-1,
.container>.spacer-2,
.container>.spacer-3 {
visibility: visible;
opacity: .4;
background: repeating-linear-gradient(45deg, #eee, #eee 5px, #fff 5px, #fff 10px);
}
</style>
</head>
<body>
Derived from: <a href="https://npm-demos.appspot.com/@polymer/[email protected]/demo/index.html">
https://npm-demos.appspot.com/@polymer/[email protected]/demo/index.html
</a>
<h1>Flexbox classes</h1>
<h2>General principals</h2>
<p>
This document defines classes that are used to create flexbox layouts based on the <a href="https://www.w3.org/TR/css-flexbox-1/">CSS Flexible Box Layout Module</a> specification. The classes defined here are designed to be used in combination to create a wide variety of layouts with no additional CSS required in most cases.
</p>
<p>
The term "container" in the flexbox specification refers to an element that contains other elements, and
the children elements of a container are referred to here as "items". An item can itself be a container of items.
</p>
<p>Two container classes are defined here, "hbox" and "vbox". Variations of the container classes are also provided, which can be added as separate classes. For example, the <code>hbox</code> class can be combined with <code>halign-items-center</code> to create a horizontal container with items aligned to the center of the available width of the container.</p>
<h4>Horizontal or Vertical Orientation</h4>
<p>
Container elements can be horizontal or vertical in orientation as determined by the class <code>hbox</code> or <code>vbox</code>, meaning the children of these containers will be arranged in rows or columns, respectively.
</p>
<p>
Note that the container in the following examples often have a larger than required fixed height to allow the items to expand vertically to fill the available space.
</p>
<div class="centered">
<demo-snippet>
<div class="container hbox" style="height:100px">
<label>class="hbox"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox" style="height: 150px">
<label>class="vbox"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
</div>
<h3>Justification versus Alignment</h3>
<p>The term "justification" in the flexbox specification refers to shifting, stretching, or spacing items in the same direction as the item orientation.
We can also shift, stretch, or space items in the "cross-axis" direction, which is the direction perpendicular to the item orientation; the flexbox specification refers to this as "alignment". </p>
<p>
Therefore, when we want to "justify" items, we would have to use flexbox style properties that are confusingly named "justify-content", "align-content", or "flex-grow".
And when we want to "align" items in the cross-axis direction, we would use flexbox style properties that are named "align-items" or "align-self" (with values of e.g. "flex-start").
</p>
<p>
Instead of using this flexbox terminology, every class that determines how we shift, stretch, or space items in a flexbox container starts with either <code>halign-</code> or <code>valign-</code>. And we determine whether "alignment" or "justification" properties are used internally based on whether the item orientation agrees with the alignment direction.
</p>
<p>
For example a container with
<code>class="<b>hbox</b> <b>halign</b>-items-center"</code> will center items in the horizontal direction, and this is also true for a container with <code>class="<b>vbox</b> <b>halign</b>-items-center"</code>.
Similarly a container with
<code>class="<b>hbox</b> <b>valign</b>-items-center"</code> will center items in the vertical direction, and this is also true for a container with <code>class="<b>vbox</b> <b>valign</b>-items-center"</code>.
</p>
<p>
By default, items are shifted to the "start"-side of the container, which is the left side of an hbox and the top side of a vbox.
Then we can add one of the <code>halign-items-*</code> classes to align items in the horizontal direction, while the <code>valign-items-*</code> classes align items in the vertical direction.
</p>
<div class="centered">
<h4>Start-justified</h4>
This is the default for hbox and vbox.
<demo-snippet>
<div class="container hbox halign-items-start" style="height: 100px">
<label>class="hbox halign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-start" style="height: 150px">
<label>class="vbox valign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Center-justified</h4>
<demo-snippet>
<div class="container hbox halign-items-center" style="height: 100px">
<label>class="hbox halign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-center" style="height: 150px">
<label>class="vbox valign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>End-justified</h4>
<demo-snippet>
<div class="container hbox halign-items-end" style="height: 100px">
<label>class="hbox halign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-end" style="height: 150px">
<label>class="vbox valign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Cross-axis start-alignment</h4>
<demo-snippet>
<div class="container hbox valign-items-start" style="height: 100px">
<label>class="hbox valign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox halign-items-start" style="height: 150px">
<label>class="vbox halign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Cross-axis center-alignment</h4>
<demo-snippet>
<div class="container hbox valign-items-center" style="height: 100px">
<label>class="hbox valign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox halign-items-center" style="height: 150px">
<label>class="vbox halign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Cross-axis end-alignment</h4>
<demo-snippet>
<div class="container hbox valign-items-end" style="height: 100px">
<label>class="hbox valign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox halign-items-end" style="height: 150px">
<label>class="vbox halign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>More alignment combos</h4>
<demo-snippet>
<div class="container hbox halign-items-center valign-items-start" style="height: 100px">
<label>class="hbox halign-items-center valign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-center valign-items-center" style="height: 100px">
<label>class="hbox halign-items-center valign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-center valign-items-end" style="height: 100px">
<label>class="hbox halign-items-center valign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-end valign-items-start" style="height: 100px">
<label>class="hbox halign-items-end valign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-end valign-items-center" style="height: 100px">
<label>class="hbox halign-items-end valign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-end valign-items-end" style="height: 100px">
<label>class="hbox halign-items-end valign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-center halign-items-start" style="height: 150px">
<label>class="vbox vbox valign-items-center halign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-center halign-items-center" style="height: 150px">
<label>class="vbox vbox valign-items-center halign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-center halign-items-end" style="height: 150px">
<label>class="vbox vbox valign-items-center halign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-end halign-items-start" style="height: 150px">
<label>class="vbox vbox valign-items-end halign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-end halign-items-center" style="height: 150px">
<label>class="vbox vbox valign-items-end halign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-end halign-items-end" style="height: 150px">
<label>class="vbox vbox valign-items-end halign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
</div>
<h3>Stretching</h3>
<p>
You'll notice above that, unless a cross-axis alignment is specified, the default behavior of flex boxes is to stretch the items in the cross-axis dimension. So by default, hbox items will stretch vertically and vbox items will stretch horizontally.
</p>
<p>
No matter what item-alignment is specified in the container, we can override the alignment for each item with a similarly-named class. For example, if we want to vertically align one item in an hbox, we can add the <code>valign-start</code> class to that item.
The next examples show the default stretch behavior, and the per-item alignment classes.
</p>
<div class="centered">
<h4>Cross-axis stretch alignment (default)</h4>
<demo-snippet>
<div class="container hbox" style="height:100px">
<label>class="hbox"</label>
<div class="valign-stretch">class="valign-stretch"</div>
<div>(default)</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox" style="height: 150px">
<label>class="vbox"</label>
<div class="halign-stretch">class="halign-stretch"</div>
<div>(default)</div>
</div>
</demo-snippet>
<h4>Per-item alignment</h4>
<demo-snippet>
<div class="container hbox" style="height: 150px">
<label>
class="hbox"
</label>
<div class="valign-start">valign-start</div>
<div class="valign-center">valign-center</div>
<div class="valign-end">valign-end</div>
<div class="valign-stretch">valign-strech</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox" style="height: 200px">
<label>
class="vbox"
</label>
<div class="halign-start">halign-start</div>
<div class="halign-center">halign-center</div>
<div class="halign-end">halign-end</div>
<div class="halign-stretch">halign-strech</div>
</div>
</demo-snippet>
<!--
<h4>More stretching combos</h4>
<demo-snippet>
<div class="container hbox halign-items-start valign-items-stretch" style="height: 100px">
<label>class="hbox halign-items-start valign-items-stretch"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-center valign-items-stretch" style="height: 100px">
<label>class="hbox halign-items-center valign-items-stretch"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox halign-items-end valign-items-stretch" style="height: 100px">
<label>class="hbox halign-items-end valign-items-stretch"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox halign-items-stretch valign-items-start" style="height: 150px">
<label>class="vbox halign-items-stretch valign-items-start"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox halign-items-stretch valign-items-center" style="height: 150px">
<label>class="vbox halign-items-stretch valign-items-center"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox halign-items-stretch valign-items-end" style="height: 150px">
<label>class="vbox halign-items-stretch valign-items-end"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
</div> -->
</div>
<h3>Main-axis stretch alignment</h3>
<p>
The default behavior of flex boxes is to <b>not</b> stretch the items in the main-axis dimension. So by default, hbox items will shrink horizontally to the minimum required and vbox items will shrink vertically.
</p>
<p>
If at least one item is specified with a <code>halign-stretch</code> or <code>valign-stretch</code> class, all the other the items in the same axis will shrink to the minimum required size, unless they are also stretched.
</p>
<p>
If you want to stretch all items in an hbox proportionately, you can do so simply by adding the <code>halign-items-stretch</code> class to the container. Or if you want to stretch a single item in the main-axis dimension of an hbox, you can add the <code>halign-stretch</code> class to that item. Similarly, if you want to stretch all items in a vbox proportionately, you can do so simply by adding the <code>valign-items-stretch</code> class to the container. Or if you want to stretch a single item in the main-axis dimension of a vbox, you can add the <code>valign-stretch</code> class to that item.
The next few examples show these classes in action.
</p>
<div class="centered">
<demo-snippet>
<div class="container hbox halign-items-stretch" style="height:100px">
<label>class="hbox halign-items-stretch"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox" style="height:100px">
<label>class="hbox"</label>
<div>one</div>
<div class="halign-stretch">
two (class="halign-stretch")</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox valign-items-stretch" style="height: 200px">
<label>class="vbox valign-items-stretch" style="height:200px"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox" style="height: 200px">
<label>class="vbox"</label>
<div>one</div>
<div class="valign-stretch">
two (class="valign-stretch")
</div>
<div>three</div>
</div>
</demo-snippet>
</div>
<h3>Stretch ratios</h3>
Each item can be stretched a different amount by adding the <code>halign-stretch-X</code> or <code>valign-stretch-X</code> classes to each item. There are only three stretch ratios: 1, 2, and 3, and the default is 1. This amount of stretching is proportional to this ratio, and to the content. The next few examples show these classes in action.
<div class="centered">
<demo-snippet>
<div class="container hbox">
<label>class="hbox"</label>
<div class="halign-stretch-1">
halign-stretch-1</div>
<div class="halign-stretch-2">
halign-stretch-2</div>
<div class="halign-stretch-3">
halign-stretch-3</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox" style="height: 200px">
<label>class="vbox"</label>
<div class="valign-stretch-1">valign-stretch-1</div>
<div class="valign-stretch-2">valign-stretch-2</div>
<div class="valign-stretch-3">valign-stretch-3</div>
</div>
</demo-snippet>
</div>
<h3>Spacing</h3>
Another way to justify or align items is by adding space between items as well as before and after. This is normally only considered to be a main-axis justification, but when wrapping of items is enabled, it is also possible to "align" the multiple rows or columns
<div class="centered">
<h4>Justification, equal space between elements</h4>
<demo-snippet>
<div class="container hbox halign-items-space-between">
<label>class="hbox halign-items-space-between"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Justification, equal space around each element</h4>
<demo-snippet>
<div class="container hbox halign-items-space-around">
<label>class="hbox halign-items-space-around"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Justification, equal space between elements and ends</h4>
<demo-snippet>
<div class="container hbox halign-items-space-evenly">
<label>class="hbox halign-items-space-evenly"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<h4>Spacer</h4>
<p>A set of spacer classes are provided as a convenience to add invisible spacing between items. You can insert one or more spacers in an hbox or vbox. (The cross-axis spacers would only apply when wrapping, but then we could not indicate which spacer would go where. So we don't need the halign- or valign- prefix.)</p>
<p>By adding spacers, you can reproduce the equal space justification classes, but you also have much more flexibility to justify and align in many more ways. There are actually four spacer classes with different expansion weights, similar to the halign-stretch-* and valign-stretch-* classes: <code>spacer</code>,
<code>spacer-1</code>,
<code>spacer-2</code>, and
<code>spacer-3</code>.
</p>
<p>While spacers are normally invisible, in the following examples, we make the spacers visible with a translucent gradient pattern.</p>
<demo-snippet>
<div class="container hbox">
<label>class="hbox"</label>
<div>one</div>
<div class="spacer"></div>
<div>two</div>
<div class="spacer"></div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox" style="height: 250px">
<label>class="vbox"</label>
<div>one</div>
<div class="spacer-1"></div>
<div>two</div>
<div class="spacer-2"></div>
<div>three</div>
<div class="spacer-3"></div>
</div>
</demo-snippet>
</div>
<h3>Reversing and ordering</h3>
<p>All the items in a container can be reversed by adding the 'reverse' class to the container. The order of the items is the reverse of the original order, and the main-axis alignment is also reversed, from start to end or vice versa.</p>
<div class="centered">
<demo-snippet>
<div class="container hbox reverse">
<label>class="hbox reverse"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox reverse" style="height:150px">
<label>class="vbox reverse"</label>
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</demo-snippet>
</div>
<h3>Wrapping</h3>
<p>Items can be wrapped by adding the 'wrap' class to the container</p>
<div class="centered">
<demo-snippet>
<div class="container hbox wrap" style="width: 100px">
<label>class="hbox wrap"</label>
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container vbox wrap" style="height: 75px">
<label>class="vbox wrap"</label>
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox reverse wrap" style="width: 100px">
<label>class="hbox reverse wrap"</label>
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox wrap halign-items-space-around"
style="width: 100px; height:100px">
<label>class="hbox wrap halign-items-space-around"</label>
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox wrap-reverse halign-items-space-around"
style="width: 100px; height:100px">
<label>class="hbox wrap-reverse halign-items-space-around"</label>
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</demo-snippet>
<demo-snippet>
<div class="container hbox wrap-reverse
halign-items-space-between
valign-items-space-between" style="width: 100px; height: 100px">
<label>class="hbox wrap-reverse
halign-items-space-between
valign-items-space-between"</label>
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</demo-snippet>
</div>
<h3>Nesting hbox and vbox</h3>
<p>Containers can be nested inside other containers. </p>
<div class="centered">
<demo-snippet>
<div class="container hbox halign-items-space-around">
<label>class="hbox halign-items-space-around"</label>
<div class="container vbox">
<label>class="vbox"</label>
<div>one</div>
<div>two</div>
</div>
<div class="container vbox">
<label>class="vbox"</label>
<div>three</div>
<div>four</div>
</div>
</div>
</demo-snippet>
</div>
</body>
</html>