forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcss-training--grid-n-flex.html
1528 lines (1432 loc) · 49.8 KB
/
css-training--grid-n-flex.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
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Training</title>
<meta name="description" content="Half day CSS training">
<meta name="author" content="Wes Ruvalcaba">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="plugin/prism/prism.css">
<link rel="stylesheet" href="plugin/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="css/theme/wes-light.css" id="theme">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
<style>
code {
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
}
.section-indicator {
position: absolute;
top: 0;
right: 0;
z-index: -1;
font-size: 0.6em;
transform: skew(-10deg);
}
.section-indicator:before {
content: '';
position: absolute;
top: -0.5em;
bottom: -0.5em;
left: -0.75em;
right: -2em;
z-index: -1;
background: rgba(35, 165, 216, 0.2);
}
section {
text-align: left;
}
</style>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section >
<p class="small" style="position: relative; top: -6em;"><strong>Pro-tip:</strong> Press <span style="display: inline-block; padding: .2em .6em; border: 1px solid #777; border-radius: .3em; background: #fff; box-shadow: 0 1px 0 #555, 0 2px 0 #555, 0 3px 0 #555, 0 4px 0 #555; position: relative; top: -.1em; color: #000;">space bar</span> to progress and it won't skip any slides</p>
<h1>
Grid and Flexbox
</h1>
</section>
<section>
<section style="position: relative">
<div style="
position: absolute;
top: 0;
right: 0;
width: 38%;
height: 100%;
overflow: hidden;
background: url(assets/me.jpg) no-repeat 45% 50%;
background-size: cover;
">
</div>
<div style="box-sizing: border-box; width: calc(65% - 0.6em);">
<h3 id="wes-ruvalcaba">Wes Ruvalcaba</h3>
<ul style="font-size: 0.8em">
<li>Developer at Giant Rabbit</li>
<li>Writing CSS since 2002</li>
<li>Markup, CSS & Standards Dork</li>
<li>Tend to write custom code, more than repurpose existing</li>
</ul>
</div>
<p style="margin-top: 1em;"><a href="https://tech.lgbt/@wesruv">tech.lgbt/@wesruv</a></p>
</section>
<section>
<h3>Feel free to ask questions at any time!</h3>
</section>
</section>
<section>
<h3>People I'm Stealing <em>a lot</em> from</h3>
<ul>
<li>Rachel Andrew</li>
<li>Chris Coyier</li>
<li>Kevin Powell</li>
<li>Mozilla Developer Network</li>
<li>... and plenty of others (see sources slides)</li>
</ul>
</section>
<section>
<section>
<h2>Document Flow & You</h2>
<aside class="notes">
Going to try and explain the intention behind CSS<br>
I'm going to take small liberties and make up some terms.
</aside>
</section>
<section>
<img src="assets/css-training/webpage.png" class="block-centered" style="width: 70%" alt="Mock up of an article page" />
<aside class="notes">
Document flow is how elements want to layout on the page, given their styles.<br>
See text flow<br>
See floated image
</aside>
</section>
<section>
<img src="assets/css-training/document-flow.png" class="block-centered" style="width: 80%" alt="Mock up of an article page" />
<aside class="notes">
This is DF<br>
They're cool<br>
Want you to be able to see all the content<br>
Read all the text<br>
Tries not to let things overlap<br>
Doesn't dig pixel perfection much<br>
Don't be mean to document flow, respecting DF pays off.
</aside>
</section>
<section data-background="assets/css-training/document-flow-bg.png" data-background-size="100% auto" data-background-position="left top">
<h3>Text Flow</h3>
<ul>
<li>How text behaves and tags like <code><strong></code> & <code><em></code></li>
<li>Inline* elements mimic text flow</li>
<li>White space matters* (*up to one space!)</li>
</ul>
<aside class="notes">
With no CSS, HTML will fall back to a textual flow<br>
Doesn’t care about widths, heights, margins, padding, etc
</aside>
</section>
<section data-background="assets/css-training/document-flow-bg.png" data-background-size="100% auto" data-background-position="left top">
<h3>Layout Flow</h3>
<ul>
<li>White space agnostic</li>
<li>Properties like:<ul>
<li>Grid</li>
<li>Flexbox</li>
<li>Table</li>
<li>CSS Columns</li>
</ul></li>
</ul>
<aside class="notes">
Composing major parts of doc<br>
The large squares/rectangles that the web is good at
</aside>
</section>
<section>
<img src="assets/css-training/webpage.png" class="block-centered" style="width: 70%" alt="Mock up of an article page" />
<aside class="notes">
Content area might be flexbox (Layout flow), but inside of the left column we go back to text flow
</aside>
</section>
<section>
<img src="assets/css-training/pos-absolute.png" class="block-centered" style="width: 80%" alt="Mock up of an article page" />
<aside class="notes">
This angry fellow represents properties that break/mess with document flow<br>
It's not wrong to break document flow, it is gutsy<br>
He'll do exactly what you say, even when it doesn't make sense<br>
Lose the safeguards of document flow that made sure content is legible<br>
He's been grumpy about all these new-fangled screen sizes<br>
Test your CSS on many screen sizes, px densities, and browsers when you bring out this guy<br>
</aside>
</section>
<section align="left" data-background="assets/css-training/pos-absolute-bg.png" data-background-size="100% auto" data-background-position="left top">
<h3 style="margin-top: 1.25em">Document Flow Breakers:</h3>
<div class="section-indicator">Document Flow</div>
<p><code>position: absolute, fixed, sticky</code></p>
<aside class="notes">
These will behave very rigidly and can cause overlap or bugs on differently sized screens.<br>
Position fixed is particularly grumpy about smaller sized screens and zooming
</aside>
</section>
<section align="left" data-background="assets/css-training/pos-absolute-bg.png" data-background-size="100% auto" data-background-position="left top">
<h3>Mess with Document Flow</h3>
<ul>
<li style="line-height: 1.8"><code>position: relative</code><br>
(when <code>top, right, bottom</code> or <code>left</code> are set)</li>
<li><code>transform</code></li>
<li>negative <code>margin</code> or <code>padding</code></li>
</ul>
<aside class="notes">
These can cause overlap and can get a little weird
</aside>
</section>
<section>
<img src="assets/css-training/webpage-modal.png" class="block-centered" style="width: 80%" alt="Mock up of an article page" />
<aside class="notes">
To get a modal like this, you have to break document flow<br>
But notice inside of it, we're back to regular document flow
</aside>
</section>
<section>
<h3>TL:Didn't think your cartoons were funny</h3>
<ul>
<li>Breaking the flow can cause complicated, hard to solve problems.</li>
<li>Try to use Flow-friendly CSS first.</li>
<li>Breaking flow isn't 'bad', but should be used sparingly and carefully.</li>
</ul>
</section>
</section>
<section>
<h2>Layout 101 in Post-CSS Grid</h2>
<aside class="notes">
We're going to start from the outside out.
</aside>
</section>
<section>
<section><h3>Floats</h3></section>
<section>
<h4>Don't use them for layout anymore*!</h4>
<p class="small" style="margin-top: 6em;">* Except for fallbacks or if you <b>know</b> better options aren't wise<br> based on your user stats.</p>
<aside class="notes">
If you can, avoid learning floats for layout, it'll go out of fashion fast<br>
They were <b>literally</b> never intended to be used for layout, we've been using CSS hacks for over a decade.
</aside>
</section>
<section align="left">
<img src="assets/css-training/document-flow.png" alt="Document flow cartoon character" style="width: 25%; float: right;" />
<h4>Are floats still good for something?</h4>
<p style="font-size: 0.75em;">Floats are great for floating elements next to a bunch of text so it will wrap. </p>
<p style="font-size: 0.5em; opacity: 0.4">Lorem ipsum dolor sit amet, wakka un blitz and chips; dolla dolla bill. Lorem ipsum dolor sit amet, wakka un flurb dolla dolla bill. Lorem ipsum dolor sit amet, wakka un flurb dolla dolla bill. Lorem ipsum dolor sit amet, wakka un blitz and chips; dolla dolla bill. Lorem ipsum dolor sit amet, wakka un flurb dolla dolla bill. Lorem ipsum dolor sit amet, wakka un flurb dolla dolla bill.</p>
<p style="font-size: 0.5em; opacity: 0.4">Lorem ipsum dolor sit amet, wakka un blitz and chips; dolla dolla bill. Lorem ipsum dolor sit amet, wakka un flurb dolla dolla bill. Lorem ipsum dolor sit amet, wakka un flurb dolla dolla bill.</p>
</section>
</section>
<section>
<div class="section-indicator">Terminology</div>
<section>
<h3>CSS Grid</h3>
<p>Basics and terminology</p>
</section>
<section>
<h4>CSS Grid</h4>
<p>Great at 2 dimensional, custom, and large scale layouts</p>
<ul>
<li>Define amount of rows and columns</li>
<li>Define constraints for rows and columns</li>
<li>Constraints can be rigid, flexible, or content based</li>
</ul>
<style>
.grid-example-wrapper {
position: relative;
transform: scale(0.9);
}
.grid-example {
position: relative;
display: grid;
width: 100%;
height: 14em;
grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
border: 0.125em dashed rgba(0, 0, 0, 0.6);
}
.grid-example > * {
position: relative;
z-index: 1;
}
.grid-example-wrapper:before,
.grid-example-wrapper:after,
.grid-example:before,
.grid-example:after {
content: '';
position: absolute;
left: 33.333%;
top: 0;
bottom: 0;
display: block;
width: 0;
border-left: 0.125em dashed rgba(0, 0, 0, 0.3);
}
.grid-example-wrapper:before {
left: 66.667%;
}
.grid-example-wrapper:after,
.grid-example:after {
top: 33.333%;
left: 0;
right: 0;
bottom: auto;
width: auto;
height: 0;
border-top: 0.125em dashed rgba(0, 0, 0, 0.3);
border-left: 0;
}
.grid-example-wrapper:after {
top: 66%;
}
.grid-example-wrapper:before,
.grid-example-wrapper:after,
.grid-example:before,
.grid-example:after {
border-color: rgba(0, 0, 0, 0.6);
}
</style>
</section>
<section>
<h4>Grid Container</h4>
<p>Element surrounding the grid.</p>
<div class="grid-example-wrapper">
<div class="grid-example" style="border: 0.25em solid #3372a1"></div>
</div>
</section>
<section>
<h4>Grid Item</h4>
<p>Direct child element of a grid container</p>
<div class="grid-example-wrapper">
<div class="grid-example" style="font-weight: bold;">
<div style="
grid-row-start: 1;
grid-row-end: 2;
grid-column-start: 1;
grid-column-end: 2;
background: rgba(255, 255, 0, 0.3);
border: 0.125em solid rgba(150, 100, 0, 0.8);
color: #664400;
display: flex;
align-items: center;
justify-content: center;">
Grid Item
</div>
<div style="
grid-row-start: 2;
grid-row-end: 4;
grid-column-start: 1;
grid-column-end: 2;
background: rgba(0, 170, 255, 0.3);
color: #005;
border: 0.125em solid rgba(0, 170, 255, 0.5);
display: flex;
align-items: center;
justify-content: center;">
Grid Item
</div>
<div style="
grid-row-start: 1;
grid-row-end: 3;
grid-column-start: 2;
grid-column-end: 4;
background: rgba(250, 100, 100, 0.3);
color: #900;
border: 0.125em solid rgba(250, 100, 100, 0.5);
display: flex;
align-items: center;
justify-content: center;">
Grid Item
</div>
</div>
</div>
</section>
<section>
<h4>Grid Line</h4>
<p>Any line in the grid</p>
<div class="grid-example-wrapper grid-example-wrapper--bold-gaps">
<div class="grid-example" style="font-weight: bold;">
<div style="
align-self: center;
text-align: center;
line-height: 1.6;
margin-top: -0.25em;
">↑<br>
← Grid Lines →<br>
↓
</div>
</div>
</div>
</section>
</section>
<section>
<section>
<h3>Beginning with Grid</h3>
</section>
<section>
<h4>Basic syntax</h4>
<pre class="language-css" style="font-size: 1em"><code class="language-css">.grid-container {
display: grid;
grid-template-columns: 25% 50% 25%;
}
</code></pre>
<style>
.grid-example-wrapper--25-50-25:before {
left: 25%;
}
.grid-example-wrapper--25-50-25 .grid-example:before {
left: 75%;
}
.grid-example-wrapper--no-rows:after,
.grid-example-wrapper--no-rows .grid-example:after {
display: none;
}
</style>
<div class="grid-example-wrapper grid-example-wrapper--25-50-25 grid-example-wrapper--no-rows">
<div class="grid-example" style="
grid-template-columns: 25% 50% 25%;
grid-template-rows: auto;
height: 4em;
"></div>
</div>
</section>
<section>
<h3><a href="assets/css-training/grid-what-if-more-content.html" target="css-training">
What if there's more content than grid areas?
</a></h3>
<a href="assets/css-training/grid-what-if-more-content.html" target="css-training">Let's see in this example...</a>
<p class="small" style="margin-top: 3em;">Grid code examples stolen/modified from <a href="http://GridByExample.com">GridByExample.com</a>, from Rachel Andrew</p>
</section>
<section>
<h4>Specifically placing a grid-item:</h4>
<pre class="language-css" style="font-size: 1em"><code class="language-css">grid-column-start: 2;
grid-column-end: 3;
grid-row-start: 1;
grid-row-end: 2;</code></pre>
</section>
<section>
<h4>Specifically placing a grid-item from the end!</h4>
<pre class="language-css" style="font-size: 1em"><code class="language-css">grid-column-start: -3;
grid-column-end: -1;
grid-row-start: -2;
grid-row-end: -1;</code></pre>
<pre class="language-css" style="font-size: 1em"><code class="language-css">grid-column-start: 1;
grid-column-end: -1;</code></pre>
</section>
</section>
<!-- <section>
<section style="text-align: center">
<h3><input type="text" size="5" value="10 min." style="text-align: right" /> Break!<br>
Be back at <input type="text" size="5" value="..." style="text-align: left" />
</h3>
<p>Try to complete as many as you can on our break<br> (try at least 5):</p>
<a href="http://cssgridgarden.com/">CSSGridGarden.com</a>
</section>
</section> -->
<section>
<!-- <section>
<h3>More CSS Grid</h3>
</section> -->
<section>
<h3>Grid Item Shorthand</h3>
<pre class="language-css"><code style="font-size: 0.85em" class="language-css">.my-header {
grid-column: 1 / -1;
}
.my-content {
grid-column: 1 / span 2;
}
.my-sidebar {
grid-row: 2;
grid-column: 3;
}</code></pre>
</section>
<section style="text-align: center;">
<div class="grid-example-wrapper grid-example-wrapper--25-50-25">
<div class="grid-example" style="
grid-template-columns: 25% 50% 25%;
grid-template-rows: repeat(3, minmax(0, 1fr));
height: 14em;
">
<div style="
grid-column: 1 / -1;
padding: 0.5em;
background: rgba(250, 50, 100, 0.5);
">Header<br><small>grid-column: 1 / -1</small></div>
<div style="
grid-column: 1 / span 2;
padding: 0.5em;
background: rgba(100, 255, 0, 0.3);
">Content<br><small>grid-column: 1 / span 2</small></div>
<div style="
grid-column: 3 / span 1;
padding: 0.5em;
background: rgba(0, 50, 100, 0.3);
">
Sidebar<small><br>
grid-row: 2;<br>
grid-column: 3;</small>
</div>
</div>
</div>
</section>
</section>
<section>
<section>
<h3>Grid Units & Helpers</h3>
</section>
<section>
<h4><code>fr</code></h4>
<p>Distributes free space in a grid track</p>
<div>
<pre class="language-css"><code class="language-css">grid-template-row: 1fr 50% 1fr;</code></pre>
<pre class="language-css"><code class="language-css">1fr 1fr /* 50% 50% (Maybe) */
1fr 2fr 1fr /* 25% 50% 25% (Maybe) */
25% 1fr 1fr /* 25% 37.5% 37.5% (Maybe) */</code></pre>
</div>
</section>
<section>
<h4><a href="assets/css-training/Example 31.html" target="css-training">
<code>minmax()</code>
</a></h4>
<pre class="language-css"><code class="language-css">display: grid;
grid-gap: 10px;
grid-template-columns:
minmax(200px, 1fr) 200px 200px;
</code></pre>
<p><a href="assets/css-training/Example 31.html" target="css-training">Example</a></p>
</section>
<section>
<h4><a href="assets/css-training/grid-repeat-example.html" target="css-training">
<code>repeat(number, size)</code>
</a></h4>
<pre class="language-css"><code class="language-css">display: grid;
grid-gap: 10px;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(3, auto);
</code></pre>
<p><a href="assets/css-training/grid-repeat-example.html" target="css-training">Example</a></p>
</section>
<section>
<h4 style="text-align: center"><a href="assets/css-training/grid-auto-fit-vs-fill.html" target="css-training">
<code>auto-fit</code> and <code>auto-fill</code>
</a></h4>
<pre class="language-css" style="font-size: 0.7em"><code class="language-css">grid-template-columns: repeat(auto-fit, 150px)</code></pre>
<div style="margin: 0 0 1em;">Will make columns fit available space.</div>
<pre class="language-css" style="font-size: 0.7em"><code class="language-css">grid-template-columns: repeat(auto-fill, 150px)</code></pre>
<div style="margin: 0 0 1em;">Will add columns as it has room for more.</div>
<aside class="notes">
This behavior is when there aren't enough grid items to fill available area
</aside>
<p><a href="assets/css-training/grid-auto-fit-vs-fill.html" target="css-training">Example</a></p>
</section>
</section>
<section>
<h3>Can I use Grid Now?</h3>
<p>Absolutely yes.</p>
</section>
<section>
<section>
<h2>CSS Grid Tips</h2>
</section>
<section>
<h3>Want equal width columns with gutter?</h3>
<p>You'd think...</p>
<pre class="language-css"><code class="language-css">.wrapper {
display: grid;
grid-template-columns: 25% 25% 25% 25%;
grid-gap: 10px;
}</code></pre>
<p><a href="assets/css-training/grid-equal-columns-wrong.html" target="css-training">
But look at what that gives you...
</a></p>
</section>
<section>
<h3>How to get equal width columns with gutter</h3>
<pre class="language-css"><code class="language-css">.wrapper {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
grid-gap: 10px;
}</code></pre>
<p><a href="assets/css-training/grid-equal-columns-correct.html" target="css-training">
Take a look...
</a></p>
</section>
<section>
<h3>Controlling auto-generated rows and columns</h3>
<pre class="language-css"><code class="language-css">.wrapper {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-template-rows: 100px 100px;
grid-gap: 10px;
/* Sets the default height for unspecified rows */
grid-auto-rows: 50px;
}</code></pre>
<p><a href="assets/css-training/grid-auto-rows.html" target="css-training">
See how it works
</a></p>
</section>
</section>
<!-- <section>
<section style="text-align: center">
<h2><input type="text" size="5" value="10 min." style="text-align: right" /> Break!<br>
Be back at <input type="text" size="5" value="..." style="text-align: left" />
</h2>
<p>Fix the equal width grid with gutters yourself:<br>
<a href="https://codepen.io/pen/RvBzrV" target="css-training">codepen.io/pen/RvBzrV</a></p>
<p>Try more <a href="https://CSSGridGarden.com" target="css-training">CSSGridGarden.com</a></p>
<p>Or explore <a href="https://GridByExample.com" target="css-training">GridByExample.com</a></p>
</section>
</section> -->
<section>
<div class="section-indicator">Terminology</div>
<section>
<h3>Flexbox</h3>
<p>Basics and terminology</p>
</section>
<section>
<h4>Flexbox</h4>
<p>Best at 1 dimensional and small scale layouts.</p>
<ul>
<li>Can direct flow of content, horizontal/vertical, reverse/regular direction</li>
<li>Can distribute extra space many ways</li>
<li>Can change displayed order of items</li>
<li>Can handle multiple rows/columns, but with less control than CSS Grid</li>
</ul>
<style>
.flex-container {
display: flex;
padding: 0.25em 0 0 0.25em;
border: 0.125em solid rgba(0, 0, 0, 0.6);
}
.flex-container > div {
min-width: 3.75em;
min-height: 3.75em;
margin: 0 0.25em 0.25em 0;
background: rgba(35, 165, 216, 0.3);
}
</style>
</section>
<section>
<h4>Flex Container</h4>
<p>Element enclosing everything</p>
<div class="flex-container" style="border-color: rgb(35, 165, 216);">
<div style="background: rgba(0, 0, 0, 0.2)"></div>
<div style="background: rgba(0, 0, 0, 0.2)"></div>
<div style="background: rgba(0, 0, 0, 0.2)"></div>
<div style="background: rgba(0, 0, 0, 0.2)"></div>
</div>
</section>
<section>
<h4>Flex Item</h4>
<style>
.flex-container--flex-items > div {
border: 0.125em solid rgba(35, 165, 216, 0.8);
}
</style>
<p>Direct child of flex container</p>
<div class="flex-container flex-container--flex-items">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
<h4>Main Axis</h4>
<p>The axis the flex items are laid out on (row/column).</p>
<div class="flex-container" style="position: relative">
<div></div>
<div></div>
<div></div>
<div></div>
<div style="
position: absolute;
top: 50%;
left: 50%;
min-width: auto;
min-height: auto;
transform: translate(-50%, -50%);
background: transparent;
font-weight: bold;
">
← Main Axis →
</div>
</div>
</section>
<section>
<h4>Cross Axis</h4>
<p>The opposite axis of the main (column/row)</p>
<div class="flex-container" style="position: relative">
<div></div>
<div></div>
<div></div>
<div style="height: 6em;"></div>
<div style="
position: absolute;
top: 50%;
left: 50%;
display: block;
min-width: 5em;
min-height: auto;
transform: translate(-50%, -50%) rotate(-90deg);
background: transparent;
font-weight: bold;
">
← Cross <div style="font-size: 1em; text-align: right">Axis →</div>
</div>
</div>
</section>
<!--
<section>
<h4>Main Start & End</h4>
<p>The beginning of the main axis is where items start from, end is the opposite side.</p>
<div class="flex-container" style="position: relative">
<div></div>
<div></div>
<div></div>
<div></div>
<div style="
position: absolute;
top: 50%;
left: 0.25em;
min-width: auto;
min-height: auto;
transform: translate(0, -50%);
background: transparent;
font-weight: bold;
">
← Main Start
</div>
<div style="
position: absolute;
top: 50%;
right: 0;
min-width: auto;
min-height: auto;
transform: translate(0, -50%);
background: transparent;
font-weight: bold;
">
Main End →
</div>
</div>
</section>
<section>
<h4>Cross Start & End</h4>
<p>The beginning of the cross axis will be top if flex is horizontal, left if it's vertical</p>
<div class="flex-container" style="position: relative">
<div></div>
<div></div>
<div></div>
<div></div>
<div style="
position: absolute;
top: 0;
left: 50%;
min-width: auto;
min-height: auto;
transform: translate(-50%, 0);
font-weight: bold;
text-align: center;
background: transparent;
">
<div style="line-height: 0.7;">↑</div>
Cross Start
</div>
<div style="
position: absolute;
bottom: 0;
left: 50%;
min-width: auto;
min-height: auto;
transform: translate(-50%, 0);
font-weight: bold;
text-align: center;
line-height: 0.8;
background: transparent;
">
Cross End<br>
<div style="line-height: 1.2;">↓</div>
</div>
</div>
<aside class="notes">
Doesn't matter if it's reverse or not, cross axis start and end will be top or left
</aside>
</section> -->
</section>
<section>
<section>
<h3>Beginning with Flexbox</h3>
</section>
<section>
<h4>Basic syntax</h4>
<pre class="language-css" style="font-size: 0.8em"><code class="language-css">.flex-container {
display: flex; /* All you need */
/* flex-direction: row; (Default) */
/* flex-wrap: nowrap; (Default) */
}
</code></pre>
<div class="flex-container" style="position: relative">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<aside class="notes">
By default flex will be row and won't wrap
</aside>
</section>
<section>
<h4>Behold, the not wrapping!</h4>
<div class="flex-container" style="position: relative">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
<h4><code>flex-wrap</code></h4>
<pre class="language-css" style="font-size: 0.8em"><code class="language-css">.flex-container {
display: flex;
/* flex-direction: row; (Default) */
flex-wrap: wrap;
}
</code></pre>
<div class="flex-container" style="flex-wrap: wrap; font-size: 0.8em;">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<aside class="notes">
By default flex will be row and won't wrap
</aside>
</section>
<section>
<h4><code>flex-direction</code></h4>
<div class="column-wrapper">
<div>
<pre class="language-css" style="font-size: 0.8em; width: 19em"><code class="language-css">.flex-container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}</code></pre>
<a href="assets/css-training/flexbox-flex-direction.html" target="css-training">Examples of <code>flex-direction</code></a>
</div>
<div class="flex-container" style="flex-direction: column; width: 4.5em; margin: auto; flex-grow: 0;">
<div></div>
<div></div>
<div></div>
</div>
</div>
</section>
<section>
<h4><code>justify-content</code></h4>
<p>How extra space is distributed along the <strong>main axis</strong></p>
<pre class="language-css" style="font-size: 0.8em"><code class="language-css">.flex-container {
display: flex;
justify-content: center;
}
</code></pre>
<div class="flex-container" style="justify-content: center;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
<h4 style="font-size: 1em;">Other <code>justify-content</code> values</h4>
<div style="font-size: 0.9em; margin-top: 0.75em; margin-bottom: 0.25em;"><code class="language-css">justify-content: flex-start;</code></div>
<div class="flex-container" style="font-size: 0.4em; justify-content: flex-start;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div style="font-size: 0.9em; margin-top: 0.75em; margin-bottom: 0.25em;"><code class="language-css">justify-content: flex-end;</code></div>
<div class="flex-container" style="font-size: 0.4em; justify-content: flex-end;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
<h4 style="font-size: 1em;">Other <code>justify-content</code> values</h4>
<div style="font-size: 0.9em; margin-top: 0.75em; margin-bottom: 0.25em;"><code class="language-css">justify-content: space-between;</code></div>
<div class="flex-container" style="font-size: 0.4em; justify-content: space-between;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div style="font-size: 0.9em; margin-top: 0.75em; margin-bottom: 0.25em;"><code class="language-css">justify-content: space-around;</code></div>
<div class="flex-container" style="font-size: 0.4em; justify-content: space-around;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div style="font-size: 0.9em; margin-top: 0.75em; margin-bottom: 0.25em;"><code class="language-css">justify-content: space-evenly;</code></div>
<div class="flex-container" style="font-size: 0.4em; justify-content: space-evenly;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
<h4><code>align-items</code></h4>
<p>How extra space is distributed along the <strong>cross axis</strong></p>
<pre class="language-css" style="font-size: 0.8em"><code class="language-css">.flex-container {
display: flex;
align-items: center;
}</code></pre>
<style>
.flex-container--align-items {position: relative;}
.flex-container--align-items > div {
min-height: 1px;
width: 25%;
padding: 0.25em;
}
</style>
<div class="flex-container flex-container--align-items" style="align-items: center;">
<div>1</div>
<div>Second item</div>
<div>I think this one is number 3</div>
<div>4</div>
</div>
</section>
<section>
<h4 style="font-size: 1em;">Other <code>align-items</code> values</h4>
<div style="font-size: 0.9em; margin-top: 0.75em; margin-bottom: 0.25em;"><code class="language-css">align-items: stretch; /* (Default) */</code></div>
<div class="flex-container flex-container--align-items" style="font-size: 0.4em; align-items: stretch;">
<div>1</div>
<div>Second item</div>
<div>I think this one is number 3</div>
<div>4</div>
</div>