Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,900 --> 00:00:03,320
So now that we know
2
00:00:03,320 --> 00:00:05,440
a little bit more about Flexbox,
3
00:00:05,440 --> 00:00:08,160
let's now keep using it in practice.
4
00:00:08,160 --> 00:00:09,570
And in this lecture,
5
00:00:09,570 --> 00:00:12,852
we will learn a little bit more about aligning flex items
6
00:00:12,852 --> 00:00:16,270
and also how to create space between them.
7
00:00:16,270 --> 00:00:19,690
And hopefully you printed out that cheat sheet from the
8
00:00:19,690 --> 00:00:24,253
last lecture, but in any way, let's now get started.
9
00:00:25,920 --> 00:00:29,470
So, in our very first lecture about Flexbox,
10
00:00:29,470 --> 00:00:32,930
we already talked about these two properties here.
11
00:00:32,930 --> 00:00:35,860
So align items and justify content,
12
00:00:35,860 --> 00:00:40,220
which are both properties that apply to the flex container.
13
00:00:40,220 --> 00:00:42,100
And now after the last lecture,
14
00:00:42,100 --> 00:00:45,651
we also know that justify content is basically to align
15
00:00:45,651 --> 00:00:49,200
items along the main axis.
16
00:00:49,200 --> 00:00:52,250
And so that's this one here, right?
17
00:00:52,250 --> 00:00:54,753
And so by default, that is horizontally.
18
00:00:55,950 --> 00:00:56,783
All right.
19
00:00:56,783 --> 00:01:00,120
So if we set this to center, for example, then you'll
20
00:01:00,120 --> 00:01:04,730
see that our items are being horizontally centered, right?
21
00:01:04,730 --> 00:01:08,470
So, again, by default, that is the main axis.
22
00:01:08,470 --> 00:01:13,470
So along this way, where I'm moving my mouse right now.
23
00:01:13,700 --> 00:01:18,700
Then we have align items which aligns items along the cross
24
00:01:19,220 --> 00:01:23,010
axis, which by default is vertically.
25
00:01:23,010 --> 00:01:25,421
And that's why if we said center,
26
00:01:25,421 --> 00:01:28,710
then these elements here are vertically centered.
27
00:01:28,710 --> 00:01:32,400
And for example, if we set it to flex start,
28
00:01:32,400 --> 00:01:35,150
then they all move to the top.
29
00:01:35,150 --> 00:01:39,440
And so, again, it's all about vertical alignment by default.
30
00:01:39,440 --> 00:01:41,420
Now I mentioned that it could switch the
31
00:01:41,420 --> 00:01:43,610
direction of these axis,
32
00:01:43,610 --> 00:01:47,163
but for now let's not get even more confused.
33
00:01:48,690 --> 00:01:51,900
So let's set it here to center and here let's actually
34
00:01:51,900 --> 00:01:55,793
set it to the default, which is flex start.
35
00:01:56,760 --> 00:01:58,780
So it's just like this.
36
00:01:58,780 --> 00:02:00,170
All right?
37
00:02:00,170 --> 00:02:03,540
So these are two of the most important properties
38
00:02:03,540 --> 00:02:06,030
that apply to the flex container.
39
00:02:06,030 --> 00:02:08,040
And another one is gap,
40
00:02:08,040 --> 00:02:11,200
but let's leave that for the end of this lecture.
41
00:02:11,200 --> 00:02:14,280
And now let's keep talking about aligning items,
42
00:02:14,280 --> 00:02:17,440
but now using the align self property,
43
00:02:17,440 --> 00:02:20,330
which applies to flex items.
44
00:02:20,330 --> 00:02:24,690
So basically using align items on the flex container
45
00:02:24,690 --> 00:02:27,150
will make it so that all the flex items
46
00:02:27,150 --> 00:02:29,430
will have the same alignment.
47
00:02:29,430 --> 00:02:32,570
So in this case, all aligned to the center.
48
00:02:32,570 --> 00:02:35,020
However, in many situations we want to
49
00:02:35,020 --> 00:02:37,850
overwrite that for one single element.
50
00:02:37,850 --> 00:02:41,890
And so for that, we use the align self property.
51
00:02:41,890 --> 00:02:46,053
So let's, for example, select our very first element here.
52
00:02:48,730 --> 00:02:51,333
So that's E L dash dash one.
53
00:02:52,620 --> 00:02:55,530
And so here, let's say that we want
54
00:02:55,530 --> 00:02:57,810
this one aligned to the top.
55
00:02:57,810 --> 00:03:02,390
And so we can say align self, and then here
56
00:03:02,390 --> 00:03:04,550
the values are the same.
57
00:03:04,550 --> 00:03:06,310
So flex start.
58
00:03:06,310 --> 00:03:07,250
And with that,
59
00:03:07,250 --> 00:03:11,820
the element and only this one moved to the very top.
60
00:03:11,820 --> 00:03:15,830
Let's try another one, for example, element four,
61
00:03:17,680 --> 00:03:22,680
for example, and let's say align self,
62
00:03:24,495 --> 00:03:27,233
and this one, let's say we want to stretch it.
63
00:03:29,040 --> 00:03:32,365
So stretch would be the default, if we didn't set it,
64
00:03:32,365 --> 00:03:36,760
let's say globally here on the flex container.
65
00:03:36,760 --> 00:03:37,910
Right?
66
00:03:37,910 --> 00:03:40,840
And so now this one is also stretched
67
00:03:40,840 --> 00:03:43,960
just like the CSS here.
68
00:03:43,960 --> 00:03:45,840
Well, let's put it on the five
69
00:03:45,840 --> 00:03:49,210
just to add some space between them.
70
00:03:49,210 --> 00:03:50,876
So now it is this one that
71
00:03:50,876 --> 00:03:53,890
goes all the way from top to bottom.
72
00:03:53,890 --> 00:03:57,453
And once again, if we changed the height of this one,
73
00:03:58,400 --> 00:04:01,320
then of course the height of here, the pink one,
74
00:04:01,320 --> 00:04:04,543
would be stretched as well to the maximum possible.
75
00:04:06,130 --> 00:04:10,490
But let's put that back and yeah.
76
00:04:10,490 --> 00:04:13,370
So this is one of the most important properties
77
00:04:13,370 --> 00:04:16,240
that we can use on the flex items.
78
00:04:16,240 --> 00:04:19,660
Let's now just very quickly also talk about the order
79
00:04:19,660 --> 00:04:23,110
property since we're already here anyway.
80
00:04:23,110 --> 00:04:26,470
So changing the order in which flex items are displayed on
81
00:04:26,470 --> 00:04:30,190
the page can be very helpful when we are adapting
82
00:04:30,190 --> 00:04:34,880
a bigger layout to a small layout for mobile screens.
83
00:04:34,880 --> 00:04:39,150
Now the default value for all elements is always zero.
84
00:04:39,150 --> 00:04:42,450
And so if we want to move an element to the very first
85
00:04:42,450 --> 00:04:45,910
position, all we need is to do is to specify
86
00:04:45,910 --> 00:04:48,960
a number that is lower than that.
87
00:04:48,960 --> 00:04:53,433
So let's try element number six here, for example,
88
00:04:55,804 --> 00:04:57,860
missing the six here.
89
00:04:59,250 --> 00:05:03,640
And again, by default, the order is zero for all of them.
90
00:05:03,640 --> 00:05:07,180
So you might think that the order is like one in the first
91
00:05:07,180 --> 00:05:12,180
one, then second, a number two and 3, 4, 5, 6, 7, 8,
92
00:05:12,250 --> 00:05:15,535
but that's not the case by default, they're all zero.
93
00:05:15,535 --> 00:05:19,510
And so if we want to move one of them to the first position,
94
00:05:19,510 --> 00:05:21,690
we simply need to give them a number
95
00:05:21,690 --> 00:05:25,590
that's lower than that, such as minus one.
96
00:05:25,590 --> 00:05:29,850
And so now the languages, which is number six,
97
00:05:29,850 --> 00:05:32,000
as we can see here, now moved
98
00:05:32,000 --> 00:05:35,020
to the very front here of the row.
99
00:05:35,020 --> 00:05:38,440
So now it became the very first element.
100
00:05:38,440 --> 00:05:40,170
And the same is true of course,
101
00:05:40,170 --> 00:05:42,833
if we want to move an element to the back.
102
00:05:44,100 --> 00:05:45,780
So let's try this one.
103
00:05:45,780 --> 00:05:50,710
And so if we specify a value that is larger than zero,
104
00:05:50,710 --> 00:05:52,660
so larger than all the other ones,
105
00:05:52,660 --> 00:05:55,480
then it will simply move to the back.
106
00:05:55,480 --> 00:05:57,600
So it will become the last one.
107
00:05:57,600 --> 00:06:01,160
And so this pink one now should become the last.
108
00:06:01,160 --> 00:06:02,998
And indeed it is.
109
00:06:02,998 --> 00:06:06,840
And if we then want to make another one the last,
110
00:06:06,840 --> 00:06:10,080
let's say this one, then we simply need
111
00:06:10,080 --> 00:06:12,840
yet another number that is even larger.
112
00:06:12,840 --> 00:06:13,943
So let's say two.
113
00:06:14,780 --> 00:06:16,193
So that is this one.
114
00:06:17,170 --> 00:06:21,870
And so now that one is the last, okay.
115
00:06:21,870 --> 00:06:26,010
But let's turn it off and yeah,
116
00:06:26,010 --> 00:06:27,680
the other ones we can actually
117
00:06:27,680 --> 00:06:31,120
leave them on just for the fun of it.
118
00:06:31,120 --> 00:06:32,570
All right?
119
00:06:32,570 --> 00:06:36,135
So that's the fundamentals of aligning.
120
00:06:36,135 --> 00:06:38,710
So here on justified content,
121
00:06:38,710 --> 00:06:42,170
there are some more values that you can experiment with.
122
00:06:42,170 --> 00:06:45,280
And again, all of them are on that cheat sheet
123
00:06:45,280 --> 00:06:48,410
that I showed you by the end of the last lecture.
124
00:06:48,410 --> 00:06:51,060
But the most prominent one, our center,
125
00:06:51,060 --> 00:06:55,590
and I would say space between or a space around as I showed
126
00:06:55,590 --> 00:06:58,393
you in the first Flexbox lecture of all.
127
00:06:59,310 --> 00:07:00,143
Great!
128
00:07:00,143 --> 00:07:03,840
So we know the fundamentals of aligning elements now,
129
00:07:03,840 --> 00:07:06,180
both vertically and horizontally.
130
00:07:06,180 --> 00:07:08,360
And now let's talk a little bit about
131
00:07:08,360 --> 00:07:10,260
adding space between them.
132
00:07:10,260 --> 00:07:12,670
So adding space manually,
133
00:07:12,670 --> 00:07:15,750
because we saw already how we can use Flexbox to
134
00:07:15,750 --> 00:07:19,300
automatically create space between flex items
135
00:07:19,300 --> 00:07:21,940
using justified content, right?
136
00:07:21,940 --> 00:07:24,960
But now I'm talking about manually creating space,
137
00:07:24,960 --> 00:07:28,593
which is most of the time, even more important actually.
138
00:07:29,450 --> 00:07:32,500
So in practice, many times we are in fact
139
00:07:32,500 --> 00:07:34,700
interested in manually defining
140
00:07:34,700 --> 00:07:37,690
space between our flex elements.
141
00:07:37,690 --> 00:07:40,933
And so there are two ways currently of doing that.
142
00:07:41,780 --> 00:07:44,020
So the original one was to simply
143
00:07:44,020 --> 00:07:48,483
add margins to the flex items like, like this.
144
00:07:50,290 --> 00:07:55,205
So selecting basically all the elements like this,
145
00:07:55,205 --> 00:07:57,870
so that will select all eight of them.
146
00:07:57,870 --> 00:08:01,730
And then let's say we can just add a margin
147
00:08:01,730 --> 00:08:05,903
to the right side off like 40 pixels.
148
00:08:07,070 --> 00:08:10,753
So give it a space, maybe a little less than that.
149
00:08:12,860 --> 00:08:14,440
Okay.
150
00:08:14,440 --> 00:08:17,815
And well, we are still overflowing the container,
151
00:08:17,815 --> 00:08:21,833
so actually let's get rid of these last two here.
152
00:08:22,910 --> 00:08:24,413
That should help a little bit.
153
00:08:25,260 --> 00:08:28,240
And yeah, that does look a bit better.
154
00:08:28,240 --> 00:08:31,980
It can also make maybe the font size here
155
00:08:31,980 --> 00:08:36,233
back to being a bit smaller or a 32.
156
00:08:37,220 --> 00:08:38,223
And yeah.
157
00:08:39,160 --> 00:08:42,570
So with this, we basically created
158
00:08:42,570 --> 00:08:47,570
30 pixels of space between all of these elements, right?
159
00:08:47,590 --> 00:08:50,670
However, now, in order to really get this right,
160
00:08:50,670 --> 00:08:54,030
we would then have to go in and remove the margin right
161
00:08:54,030 --> 00:08:58,170
From the very last element, which can be a bit of a pain.
162
00:08:58,170 --> 00:09:00,090
So it's an extra step.
163
00:09:00,090 --> 00:09:04,750
And also it's way nicer to have the definition of a gap
164
00:09:04,750 --> 00:09:08,140
between these elements right here in the container.
165
00:09:08,140 --> 00:09:11,440
So then we have basically all the definitions of how the
166
00:09:11,440 --> 00:09:14,704
flex items look like right there in the container element.
167
00:09:14,704 --> 00:09:18,610
And again, that is actually a lot nicer.
168
00:09:18,610 --> 00:09:21,630
So maybe that doesn't make sense at this point,
169
00:09:21,630 --> 00:09:24,560
but you will see with practice that it is actually
170
00:09:24,560 --> 00:09:27,540
a good practice or it's actually helpful
171
00:09:27,540 --> 00:09:30,810
to have all of this in the flex container.
172
00:09:30,810 --> 00:09:34,770
And so therefore a new property was added to Flexbox,
173
00:09:34,770 --> 00:09:36,810
which is called gap.
174
00:09:36,810 --> 00:09:39,813
So we can remove this here.
175
00:09:41,000 --> 00:09:44,700
Then we are back to the beginning and then
176
00:09:44,700 --> 00:09:48,540
we can very simply add the gap property
177
00:09:48,540 --> 00:09:51,713
and set it to 30 pixels as well.
178
00:09:52,610 --> 00:09:54,460
And there we go.
179
00:09:54,460 --> 00:09:57,583
So we are back to having the same gap basically,
180
00:09:57,583 --> 00:10:00,900
but now it is nicely in the flex container.
181
00:10:00,900 --> 00:10:03,360
And also if we inspect this,
182
00:10:03,360 --> 00:10:06,340
we see that none of them has any margins.
183
00:10:06,340 --> 00:10:07,747
And so there's no need to then
184
00:10:07,747 --> 00:10:11,330
remove the margin from the last element there.
185
00:10:11,330 --> 00:10:12,380
All right.
186
00:10:12,380 --> 00:10:16,410
And I think that's actually it for the fundamentals of
187
00:10:16,410 --> 00:10:20,690
aligning and creating space between elements.
188
00:10:20,690 --> 00:10:23,070
And all of this will make more sense of course,
189
00:10:23,070 --> 00:10:26,890
once we move from these like abstract boxes here
190
00:10:26,890 --> 00:10:28,750
to some real world example.
191
00:10:28,750 --> 00:10:32,070
For example, our project, right?
192
00:10:32,070 --> 00:10:36,970
But for now we will keep working on this small demo here.
193
00:10:36,970 --> 00:10:38,200
And in the next lecture,
194
00:10:38,200 --> 00:10:41,370
we will talk about one of the most important properties,
195
00:10:41,370 --> 00:10:43,770
which is the flex property.
196
00:10:43,770 --> 00:10:46,860
So stay tuned for that and then after that,
197
00:10:46,860 --> 00:10:49,433
we will finally return to our project.
14789
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.