Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,450 --> 00:00:02,700
Let's now define
2
00:00:02,700 --> 00:00:07,470
what exactly flexbox is and when and why we need it.
3
00:00:07,470 --> 00:00:10,420
And also talk about some important terminology
4
00:00:10,420 --> 00:00:11,870
around flexbox.
5
00:00:11,870 --> 00:00:16,200
And finally also get an overview of all the properties
6
00:00:16,200 --> 00:00:19,413
that are part of the flexbox specification.
7
00:00:21,600 --> 00:00:25,710
So a one line definition of flexbox is that it is
8
00:00:25,710 --> 00:00:29,640
a set of related CSS properties that we can use
9
00:00:29,640 --> 00:00:32,780
to build one-dimensional layouts.
10
00:00:32,780 --> 00:00:36,300
Now, when flexbox was developed a couple of years ago,
11
00:00:36,300 --> 00:00:40,550
the main idea behind it was to basically allow browsers
12
00:00:40,550 --> 00:00:43,420
to automatically divide empty space
13
00:00:43,420 --> 00:00:48,270
inside some container element by its child elements.
14
00:00:48,270 --> 00:00:49,167
And by doing that,
15
00:00:49,167 --> 00:00:52,700
the browser takes away a lot of work that previously
16
00:00:52,700 --> 00:00:54,660
the web developers had to do.
17
00:00:54,660 --> 00:00:58,770
So by defining manually width and stuff like that.
18
00:00:58,770 --> 00:01:02,180
So a bit like we did in our last coding challenge.
19
00:01:02,180 --> 00:01:05,800
So with flexbox, all of that would happen automatically.
20
00:01:05,800 --> 00:01:08,932
Now flexbox also makes it extremely easy
21
00:01:08,932 --> 00:01:11,370
to automatically align items
22
00:01:11,370 --> 00:01:15,030
to one another inside a certain parent container.
23
00:01:15,030 --> 00:01:19,040
And that is true both horizontally and vertically.
24
00:01:19,040 --> 00:01:21,220
And in fact, we already saw that working
25
00:01:21,220 --> 00:01:24,610
a little bit in the previous lecture, right?
26
00:01:24,610 --> 00:01:27,510
And so with this, flexbox solves
27
00:01:27,510 --> 00:01:31,260
a couple of very common problems in CSS development,
28
00:01:31,260 --> 00:01:33,410
such as vertical centering
29
00:01:33,410 --> 00:01:36,530
and also creating equal height columns.
30
00:01:36,530 --> 00:01:40,700
So these used to be hard problems before flexbox came along,
31
00:01:40,700 --> 00:01:43,100
but now with modern CSS,
32
00:01:43,100 --> 00:01:45,810
these are very, very simple to solve.
33
00:01:45,810 --> 00:01:48,770
And so since you are learning CSS only now
34
00:01:48,770 --> 00:01:51,983
with these modern technologies already in place,
35
00:01:51,983 --> 00:01:55,800
you will never know how difficult this used to be.
36
00:01:55,800 --> 00:01:59,190
So consider yourself very lucky by that.
37
00:01:59,190 --> 00:02:03,020
So basically what I just said is that flexbox
38
00:02:03,020 --> 00:02:07,070
is perfect for replacing the old school floats.
39
00:02:07,070 --> 00:02:09,496
And by that it allows us to write fewer
40
00:02:09,496 --> 00:02:13,430
and also cleaner HTML and CSS code,
41
00:02:13,430 --> 00:02:16,650
which of course is very easy to maintain websites
42
00:02:16,650 --> 00:02:19,903
over the long run and to write less bucks.
43
00:02:20,740 --> 00:02:25,210
Okay. So now that we know what flexbox is exactly
44
00:02:25,210 --> 00:02:27,710
and what problems it helps us solve.
45
00:02:27,710 --> 00:02:31,013
Let's talk a little bit about some important terminology.
46
00:02:32,730 --> 00:02:36,660
And actually there are not many concepts behind flexbox
47
00:02:36,660 --> 00:02:40,460
that you need to understand in order to start using it.
48
00:02:40,460 --> 00:02:43,360
But here is what you do need to know.
49
00:02:43,360 --> 00:02:44,540
So, first of all,
50
00:02:44,540 --> 00:02:47,470
the element on which we want to use flexbox
51
00:02:47,470 --> 00:02:50,010
is called the flex container.
52
00:02:50,010 --> 00:02:53,006
So just as I mentioned in the last lecture as well,
53
00:02:53,006 --> 00:02:56,800
and all we have to do in order to create a flex container
54
00:02:56,800 --> 00:03:01,800
is to set its display property to flex. And that's it.
55
00:03:01,840 --> 00:03:04,690
That's how we get started with flexbox.
56
00:03:04,690 --> 00:03:06,190
So if we do this,
57
00:03:06,190 --> 00:03:10,039
then all the direct children of that flex container
58
00:03:10,039 --> 00:03:13,484
will become the so-called flex items.
59
00:03:13,484 --> 00:03:17,480
And this is actually important to know, and to keep in mind,
60
00:03:17,480 --> 00:03:19,600
because we will use different properties
61
00:03:19,600 --> 00:03:23,730
on the flex container and on the flex items.
62
00:03:23,730 --> 00:03:27,580
Now, the direction in which these flex items are laid out
63
00:03:27,580 --> 00:03:29,750
is called the main axis,
64
00:03:29,750 --> 00:03:33,100
which is represented with this arrow here.
65
00:03:33,100 --> 00:03:35,562
Then the other perpendicular axis
66
00:03:35,562 --> 00:03:38,860
is simply called the cross axis.
67
00:03:38,860 --> 00:03:41,460
And it's important to know about these names
68
00:03:41,460 --> 00:03:43,920
because we can actually change the direction
69
00:03:43,920 --> 00:03:48,840
of the main axis, and so therefore also of the cross axis.
70
00:03:48,840 --> 00:03:52,510
Plus we can align elements along the main axis
71
00:03:52,510 --> 00:03:55,690
and along the cross axis in different ways.
72
00:03:55,690 --> 00:03:57,680
And therefore we always need to know
73
00:03:57,680 --> 00:03:59,933
which axis we are dealing with.
74
00:04:00,820 --> 00:04:03,530
So try to keep these concepts in mind
75
00:04:03,530 --> 00:04:05,590
so that you can fully understand
76
00:04:05,590 --> 00:04:09,210
how the different flexbox related properties work.
77
00:04:09,210 --> 00:04:12,303
And actually that's what we're going to talk about next.
78
00:04:14,040 --> 00:04:15,120
So in this slide,
79
00:04:15,120 --> 00:04:17,930
before we actually move to the practice part,
80
00:04:17,930 --> 00:04:21,590
I want to show you an overview of all the CSS properties
81
00:04:21,590 --> 00:04:25,060
that are part of the flexbox specification,
82
00:04:25,060 --> 00:04:29,530
both for the flex container and for the flex items.
83
00:04:29,530 --> 00:04:31,300
So for the flex container,
84
00:04:31,300 --> 00:04:35,530
the most important ones are the gap, the justify-content
85
00:04:35,530 --> 00:04:38,210
and the align-items properties.
86
00:04:38,210 --> 00:04:40,870
And in fact, we already talked about two of them
87
00:04:40,870 --> 00:04:43,560
in the last lecture, right?
88
00:04:43,560 --> 00:04:46,800
Now I'm not going to go over all the details here,
89
00:04:46,800 --> 00:04:49,701
just know that the first value that is in bold
90
00:04:49,701 --> 00:04:52,890
is the default value and then the other ones
91
00:04:52,890 --> 00:04:56,030
are the possible options that we can specify.
92
00:04:56,030 --> 00:04:59,040
And then also you have a very short description
93
00:04:59,040 --> 00:05:01,160
of each of the properties.
94
00:05:01,160 --> 00:05:04,564
And so my hope is that you can use this slide
95
00:05:04,564 --> 00:05:08,270
kind of as a cheat sheet to print out,
96
00:05:08,270 --> 00:05:10,560
or to create a print screen image
97
00:05:10,560 --> 00:05:12,350
that you can always have handy
98
00:05:12,350 --> 00:05:14,850
when you are working with flexbox.
99
00:05:14,850 --> 00:05:16,670
I actually did this in the very beginning
100
00:05:16,670 --> 00:05:18,830
when I started learning flexbox
101
00:05:18,830 --> 00:05:21,150
and it was really, really helpful
102
00:05:21,150 --> 00:05:24,340
because it is in fact impossible to know
103
00:05:24,340 --> 00:05:27,440
all of these properties by heart at all times,
104
00:05:27,440 --> 00:05:29,910
and also know exactly what they do.
105
00:05:29,910 --> 00:05:32,670
So again, I think it would be a great idea
106
00:05:32,670 --> 00:05:36,200
to print out the slide and keep it as a cheat sheet,
107
00:05:36,200 --> 00:05:39,720
close to your keyboard or whatever you use
108
00:05:39,720 --> 00:05:41,810
on your working space.
109
00:05:41,810 --> 00:05:45,110
But anyway, there are three other properties
110
00:05:45,110 --> 00:05:48,308
that we can apply on the flex container element,
111
00:05:48,308 --> 00:05:53,308
which are flex-direction, flex-wrap, and align-content.
112
00:05:53,480 --> 00:05:57,620
And actually some of these, especially number five and six
113
00:05:57,620 --> 00:06:01,450
are used for pretty advanced flexbox techniques
114
00:06:01,450 --> 00:06:03,780
that we will not study in this course,
115
00:06:03,780 --> 00:06:08,080
because I think they're a bit too confusing for beginners.
116
00:06:08,080 --> 00:06:11,860
So in this course, which is more of a beginner CSS course,
117
00:06:11,860 --> 00:06:14,640
my goal is just that you really understand
118
00:06:14,640 --> 00:06:16,335
the fundamentals of flexbox
119
00:06:16,335 --> 00:06:19,070
and are able to use them on your own.
120
00:06:19,070 --> 00:06:21,680
And with these fundamentals, trust me,
121
00:06:21,680 --> 00:06:26,660
you can solve 99% of all the most common scenarios.
122
00:06:26,660 --> 00:06:29,040
But now moving on a bit to properties
123
00:06:29,040 --> 00:06:32,295
that we can apply on the flex items themselves,
124
00:06:32,295 --> 00:06:36,278
one of them is align-auto, which is pretty important
125
00:06:36,278 --> 00:06:38,900
because this can basically override
126
00:06:38,900 --> 00:06:41,270
the align-items property.
127
00:06:41,270 --> 00:06:44,640
Then we have these other ones which are flex-grow,
128
00:06:44,640 --> 00:06:48,652
flex-shrink, flex-basis, and these three together,
129
00:06:48,652 --> 00:06:53,590
so two, three and four form the flex property.
130
00:06:53,590 --> 00:06:56,310
So as you can see below, number five there,
131
00:06:56,310 --> 00:07:00,530
flex is the recommended shorthand for flex-grow,
132
00:07:00,530 --> 00:07:03,740
flex-shrink and flex-basis.
133
00:07:03,740 --> 00:07:06,430
Okay. And again, we will go over them
134
00:07:06,430 --> 00:07:08,760
a little bit later in the section.
135
00:07:08,760 --> 00:07:12,730
Once we actually can start using them in practice.
136
00:07:12,730 --> 00:07:15,360
Finally, there is also the order property,
137
00:07:15,360 --> 00:07:18,400
which we can use to basically change the order
138
00:07:18,400 --> 00:07:21,130
of the flex items visually on the page
139
00:07:21,130 --> 00:07:24,780
without changing their order in the source code.
140
00:07:24,780 --> 00:07:25,640
Okay.
141
00:07:25,640 --> 00:07:28,809
But enough talking now let's now move back to code
142
00:07:28,809 --> 00:07:32,863
and start learning many of these properties, one by one.
10950
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.