Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,550 --> 00:00:04,210
All right. So let's now use
2
00:00:04,210 --> 00:00:06,460
all our Flexbox knowledge
3
00:00:06,460 --> 00:00:09,240
in order to build the overall page layout
4
00:00:09,240 --> 00:00:10,763
using Flexbox.
5
00:00:12,470 --> 00:00:14,870
And actually that shouldn't be too hard
6
00:00:14,870 --> 00:00:16,630
for us at this point,
7
00:00:16,630 --> 00:00:19,653
because the layout is actually quite simple.
8
00:00:21,460 --> 00:00:25,400
So let's now make this a bit bigger again.
9
00:00:25,400 --> 00:00:27,420
And so remember that the layout
10
00:00:27,420 --> 00:00:30,113
we are trying to achieve is simply this.
11
00:00:30,950 --> 00:00:34,179
So basically the header and the footer
12
00:00:34,179 --> 00:00:36,470
are going to stay in place.
13
00:00:36,470 --> 00:00:39,530
So they are already perfect right now.
14
00:00:39,530 --> 00:00:41,040
And so all we need to do
15
00:00:41,040 --> 00:00:41,940
is to put
16
00:00:43,940 --> 00:00:45,900
this article
17
00:00:45,900 --> 00:00:49,000
side-by-side with the related posts.
18
00:00:49,000 --> 00:00:51,030
And these related posts, remember,
19
00:00:51,030 --> 00:00:54,120
should have a width of 300 pixels.
20
00:00:54,120 --> 00:00:55,740
And then we want a gap
21
00:00:55,740 --> 00:00:59,390
here in the middle of 75 pixels.
22
00:00:59,390 --> 00:01:00,690
Okay.
23
00:01:00,690 --> 00:01:03,230
So let's do that. And again,
24
00:01:03,230 --> 00:01:04,820
what we need to do is basically
25
00:01:04,820 --> 00:01:06,730
only put this element here,
26
00:01:06,730 --> 00:01:09,500
side-by-side with this article.
27
00:01:09,500 --> 00:01:10,740
And so once again,
28
00:01:10,740 --> 00:01:13,037
the first question to ask is,
29
00:01:13,037 --> 00:01:16,460
"What is going to be our flex container?"
30
00:01:16,460 --> 00:01:20,240
So is it maybe the container element?
31
00:01:20,240 --> 00:01:23,563
So the element with the class of container?
32
00:01:24,510 --> 00:01:27,090
Well, let's go to the top of the page
33
00:01:27,090 --> 00:01:28,383
and let's try it out.
34
00:01:30,480 --> 00:01:33,096
Display flex, and, well,
35
00:01:33,096 --> 00:01:36,170
it doesn't look like
36
00:01:36,170 --> 00:01:37,683
that was the correct solution.
37
00:01:38,520 --> 00:01:39,620
So now everything here
38
00:01:39,620 --> 00:01:41,830
is kind of side-by-side
39
00:01:41,830 --> 00:01:43,910
and that makes sense.
40
00:01:43,910 --> 00:01:44,970
So the reason for that
41
00:01:44,970 --> 00:01:47,810
is that all of these, so the header,
42
00:01:47,810 --> 00:01:50,530
the article to your site, and the footer,
43
00:01:50,530 --> 00:01:51,680
all of them are actually
44
00:01:51,680 --> 00:01:54,640
children of this container.
45
00:01:54,640 --> 00:01:56,010
And so of course,
46
00:01:56,010 --> 00:01:58,510
this is not our flex container
47
00:01:58,510 --> 00:02:00,120
we are looking for.
48
00:02:00,120 --> 00:02:02,320
Instead, what we will have to do
49
00:02:02,320 --> 00:02:04,420
is to create a new one.
50
00:02:04,420 --> 00:02:06,500
So with Flexbox, many times,
51
00:02:06,500 --> 00:02:09,870
it is necessary to create a new flex container
52
00:02:09,870 --> 00:02:12,560
in order to achieve our layouts.
53
00:02:12,560 --> 00:02:14,650
So remember, in the last lecture,
54
00:02:14,650 --> 00:02:17,000
we actually had to do the same thing here
55
00:02:17,000 --> 00:02:19,150
for each related post.
56
00:02:19,150 --> 00:02:22,150
So we had to create a new div here
57
00:02:22,150 --> 00:02:23,220
so that this div
58
00:02:23,220 --> 00:02:25,743
could then be side-by-side with the image.
59
00:02:26,670 --> 00:02:29,050
So that's not the same situation actually,
60
00:02:29,050 --> 00:02:30,310
but we still had to create
61
00:02:30,310 --> 00:02:31,810
a new element in order
62
00:02:31,810 --> 00:02:33,750
to achieve our layout.
63
00:02:33,750 --> 00:02:37,600
So that's again, quite common using Flexbox.
64
00:02:37,600 --> 00:02:40,280
But anyway, now we want to create
65
00:02:40,280 --> 00:02:44,417
a parent for both the article and the aside.
66
00:02:45,550 --> 00:02:48,460
So let's create a new div here.
67
00:02:48,460 --> 00:02:52,090
So again, an element without a real meaning,
68
00:02:52,090 --> 00:02:55,520
and this one I'm going to call it just "row".
69
00:02:55,520 --> 00:02:57,420
So a very generic name,
70
00:02:57,420 --> 00:02:59,120
which we could reuse all over
71
00:02:59,120 --> 00:03:00,973
the page if we want it.
72
00:03:01,890 --> 00:03:04,350
So let's remove this one from here
73
00:03:05,270 --> 00:03:08,373
and paste it after the end of the aside.
74
00:03:09,310 --> 00:03:12,273
So here ends the article, then starts the aside.
75
00:03:13,110 --> 00:03:16,000
And then after the aside and before the footer,
76
00:03:16,000 --> 00:03:17,510
is where we close the div
77
00:03:18,470 --> 00:03:21,393
give it a save and then it reformats everything.
78
00:03:22,640 --> 00:03:25,290
And so let's then go down
79
00:03:25,290 --> 00:03:28,294
here to the end of our code
80
00:03:28,294 --> 00:03:30,253
and start building the layout.
81
00:03:32,560 --> 00:03:35,693
So our row is now the flex container.
82
00:03:39,440 --> 00:03:42,860
And so this is what it looks like.
83
00:03:42,860 --> 00:03:43,890
And actually,
84
00:03:43,890 --> 00:03:48,100
that already looks pretty good, just like this.
85
00:03:48,100 --> 00:03:50,913
So without having to do a lot of work actually.
86
00:03:52,320 --> 00:03:54,750
Now let's just inspect there's this aside,
87
00:03:54,750 --> 00:03:57,223
because it looks like it already has a width,
88
00:03:59,150 --> 00:04:02,160
but well, actually it doesn't.
89
00:04:02,160 --> 00:04:04,210
So does this just a Flexbox's
90
00:04:04,210 --> 00:04:06,230
automatic position,
91
00:04:06,230 --> 00:04:07,740
basically automatically trying
92
00:04:07,740 --> 00:04:11,490
to figure out the perfect width for this element.
93
00:04:11,490 --> 00:04:14,470
So apparently that's 281 pixels,
94
00:04:14,470 --> 00:04:17,930
but what we wanted to be is 300 pixels.
95
00:04:17,930 --> 00:04:19,860
So just like we did before,
96
00:04:19,860 --> 00:04:22,680
when we did it with floats.
97
00:04:22,680 --> 00:04:23,513
Right?
98
00:04:24,360 --> 00:04:26,350
So let's specify the width
99
00:04:26,350 --> 00:04:27,603
of the aside.
100
00:04:29,220 --> 00:04:32,230
And now remember that for flex items,
101
00:04:32,230 --> 00:04:34,380
we should not use the width property,
102
00:04:34,380 --> 00:04:37,393
but instead use the flex spaces.
103
00:04:38,730 --> 00:04:41,443
So that would be flex spaces,
104
00:04:42,670 --> 00:04:44,810
300 pixels.
105
00:04:44,810 --> 00:04:46,790
Let's see if that works,
106
00:04:46,790 --> 00:04:49,120
and it doesn't seem to work,
107
00:04:49,120 --> 00:04:50,120
right?
108
00:04:50,120 --> 00:04:52,940
So it's still at 281.
109
00:04:52,940 --> 00:04:54,988
And the reason for that must be
110
00:04:54,988 --> 00:04:57,240
is that Flexbox like to automatically
111
00:04:57,240 --> 00:04:59,690
shrink these elements.
112
00:04:59,690 --> 00:05:03,030
So we need to set a flex shrink to zero,
113
00:05:03,030 --> 00:05:04,500
remember that,
114
00:05:04,500 --> 00:05:05,870
and we should actually do
115
00:05:05,870 --> 00:05:07,810
all of that in the shorthand
116
00:05:07,810 --> 00:05:09,483
flex property anyway.
117
00:05:11,530 --> 00:05:14,060
So just flex.
118
00:05:14,060 --> 00:05:18,140
And then the first one remember is flex grow.
119
00:05:18,140 --> 00:05:20,510
And let's check that out here.
120
00:05:20,510 --> 00:05:22,270
And actually I will copy it here
121
00:05:22,270 --> 00:05:25,053
because this can be a source of confusion.
122
00:05:27,910 --> 00:05:28,763
Okay.
123
00:05:30,520 --> 00:05:32,640
So just formatting it here quickly
124
00:05:34,820 --> 00:05:37,270
to make it look a bit better.
125
00:05:37,270 --> 00:05:39,150
And so here's the default
126
00:05:39,150 --> 00:05:40,770
of flex grow is zero.
127
00:05:40,770 --> 00:05:42,187
And we want to keep that
128
00:05:42,187 --> 00:05:44,920
and default of flex shrink is one,
129
00:05:44,920 --> 00:05:47,010
but let's set that also to zero
130
00:05:47,010 --> 00:05:48,910
to force it to be exactly
131
00:05:48,910 --> 00:05:50,523
300 pixels wide.
132
00:05:51,500 --> 00:05:54,640
And so maybe you saw it that it grew.
133
00:05:54,640 --> 00:05:57,853
And indeed now we have our 300 pixels.
134
00:05:58,750 --> 00:06:00,070
All right?
135
00:06:00,070 --> 00:06:01,180
And now let's actually
136
00:06:01,180 --> 00:06:03,543
format the article as well.
137
00:06:07,340 --> 00:06:10,270
So that's this other column basically.
138
00:06:10,270 --> 00:06:13,440
And for now let's do it in a similar way.
139
00:06:13,440 --> 00:06:15,070
So setting these to zero
140
00:06:15,070 --> 00:06:19,260
and then specifying exactly 825 pixels,
141
00:06:19,260 --> 00:06:21,270
just like we did before.
142
00:06:21,270 --> 00:06:24,200
So that's going to be 825,
143
00:06:24,200 --> 00:06:27,820
plus a 75 pixels of space between them.
144
00:06:27,820 --> 00:06:30,433
And then plus the 300 pixels right here.
145
00:06:31,490 --> 00:06:33,340
So let's do it like this for now,
146
00:06:33,340 --> 00:06:35,140
but we will change that a bit later.
147
00:06:37,170 --> 00:06:38,440
Okay.
148
00:06:38,440 --> 00:06:41,620
And now let's add that gap here in between,
149
00:06:41,620 --> 00:06:43,050
so that's space,
150
00:06:43,050 --> 00:06:45,600
and so for that on the flex container,
151
00:06:45,600 --> 00:06:48,900
remember we can use the gap property.
152
00:06:48,900 --> 00:06:53,670
So let's set that to 75 pixel just like before.
153
00:06:53,670 --> 00:06:57,563
And so now our layout is basically done.
154
00:06:58,920 --> 00:07:00,283
Let's check that out.
155
00:07:01,160 --> 00:07:06,160
So 300 pixels and this one has our 825 pixels.
156
00:07:06,870 --> 00:07:08,660
And so everything added together
157
00:07:08,660 --> 00:07:11,210
gives us our 1200 pixels,
158
00:07:11,210 --> 00:07:13,033
which is the width of the container.
159
00:07:13,960 --> 00:07:16,090
Now having to do all this math
160
00:07:16,090 --> 00:07:17,700
kind of defeats the purpose
161
00:07:17,700 --> 00:07:20,670
of using Flexbox in the first place.
162
00:07:20,670 --> 00:07:23,540
And so maybe we just want the aside
163
00:07:23,540 --> 00:07:27,470
to be really this size, but then the article,
164
00:07:27,470 --> 00:07:29,310
maybe we can allow Flexbox
165
00:07:29,310 --> 00:07:32,560
to automatically figure out its size.
166
00:07:32,560 --> 00:07:34,130
Right?
167
00:07:34,130 --> 00:07:35,370
So usually what we do
168
00:07:35,370 --> 00:07:37,180
in a situation like this
169
00:07:37,180 --> 00:07:39,810
is to simply set flex to one,
170
00:07:39,810 --> 00:07:41,490
which will then automatically allow
171
00:07:41,490 --> 00:07:43,730
this element to grow as much
172
00:07:43,730 --> 00:07:46,700
as it can in the available space.
173
00:07:46,700 --> 00:07:49,020
And so if we give this a save,
174
00:07:49,020 --> 00:07:50,860
then our element should actually look
175
00:07:50,860 --> 00:07:53,880
exactly the same as before.
176
00:07:53,880 --> 00:07:56,110
And indeed it does.
177
00:07:56,110 --> 00:07:58,990
So it's still 825 pixels wide
178
00:07:58,990 --> 00:08:01,040
because that is simply the space
179
00:08:01,040 --> 00:08:02,850
that is available for it.
180
00:08:02,850 --> 00:08:05,140
And so well that's done exactly
181
00:08:05,140 --> 00:08:06,989
the space that it can fill.
182
00:08:06,989 --> 00:08:09,090
Okay.
183
00:08:09,090 --> 00:08:12,740
Now let's just figure out what happens down here.
184
00:08:12,740 --> 00:08:14,410
And maybe you have noticed
185
00:08:14,410 --> 00:08:16,330
that this aside here grew
186
00:08:16,330 --> 00:08:18,670
all the way to the bottom.
187
00:08:18,670 --> 00:08:22,120
So we will take a look at why that happens,
188
00:08:22,120 --> 00:08:23,080
but you also see
189
00:08:23,080 --> 00:08:25,270
that it actually grew a bit more
190
00:08:26,150 --> 00:08:28,090
so almost here to the end.
191
00:08:28,090 --> 00:08:29,080
And the reason for that,
192
00:08:29,080 --> 00:08:31,840
is that this article has some margin here,
193
00:08:31,840 --> 00:08:34,710
which we also added way back.
194
00:08:34,710 --> 00:08:35,850
And so one more time,
195
00:08:35,850 --> 00:08:37,646
this margin is kind of part
196
00:08:37,646 --> 00:08:40,110
of the size of this element.
197
00:08:40,110 --> 00:08:42,803
And so let's now actually remove that here.
198
00:08:45,520 --> 00:08:48,913
So margin bottom zero.
199
00:08:50,040 --> 00:08:51,430
Okay.
200
00:08:51,430 --> 00:08:53,610
And instead to create some space
201
00:08:53,610 --> 00:08:56,240
here between the footer and this content,
202
00:08:56,240 --> 00:08:59,980
let's add that margin bottom to the entire row.
203
00:08:59,980 --> 00:09:01,970
So to this container.
204
00:09:01,970 --> 00:09:02,870
Right?
205
00:09:02,870 --> 00:09:04,210
But what matters is that,
206
00:09:04,210 --> 00:09:06,020
now this is at least
207
00:09:06,020 --> 00:09:09,502
kind of aligned to this one, right?
208
00:09:09,502 --> 00:09:10,713
So,
209
00:09:11,810 --> 00:09:15,653
margin bottom of 60 pixels.
210
00:09:17,000 --> 00:09:18,320
Nice.
211
00:09:18,320 --> 00:09:19,650
And now let's think
212
00:09:19,650 --> 00:09:21,870
why actually this element grew
213
00:09:21,870 --> 00:09:23,913
all the way until the bottom here.
214
00:09:25,100 --> 00:09:28,400
So can you think why that is happening?
215
00:09:28,400 --> 00:09:30,160
Well, the reason is that
216
00:09:30,160 --> 00:09:32,950
remember how the default value for a line
217
00:09:32,950 --> 00:09:35,160
items is stretched?
218
00:09:35,160 --> 00:09:38,340
So basically if we don't define a line items,
219
00:09:38,340 --> 00:09:40,490
then automatically all the elements
220
00:09:40,490 --> 00:09:43,210
will stretch as far as they can.
221
00:09:43,210 --> 00:09:44,268
And in this case, the largest element
222
00:09:44,268 --> 00:09:47,520
is this aside here,
223
00:09:47,520 --> 00:09:49,230
or actually this article,
224
00:09:49,230 --> 00:09:52,423
which we can see if we add a color to it.
225
00:09:54,380 --> 00:09:57,501
So background color
226
00:09:57,501 --> 00:09:58,613
red.
227
00:10:00,840 --> 00:10:02,130
So you'll see that this element
228
00:10:02,130 --> 00:10:04,130
of course is way larger.
229
00:10:04,130 --> 00:10:05,610
And so then by default,
230
00:10:05,610 --> 00:10:07,550
all other flex items grow
231
00:10:07,550 --> 00:10:09,210
as much as they can
232
00:10:09,210 --> 00:10:11,540
in order to have the same size.
233
00:10:11,540 --> 00:10:13,610
So you see, they're perfectly aligned
234
00:10:13,610 --> 00:10:14,673
here at the bottom.
235
00:10:15,520 --> 00:10:16,420
Now, many times,
236
00:10:16,420 --> 00:10:20,070
this is exactly the behavior that we want.
237
00:10:20,070 --> 00:10:23,950
And before Flexbox, with just float layouts,
238
00:10:23,950 --> 00:10:25,240
this kind of layout
239
00:10:25,240 --> 00:10:28,210
was actually almost impossible to achieve
240
00:10:28,210 --> 00:10:30,270
with CSS alone.
241
00:10:30,270 --> 00:10:32,760
But now as you see, it's very easy.
242
00:10:32,760 --> 00:10:35,270
It even happens by default.
243
00:10:35,270 --> 00:10:36,560
Right?
244
00:10:36,560 --> 00:10:38,160
Now in this situation,
245
00:10:38,160 --> 00:10:40,640
let's say, we don't want that.
246
00:10:40,640 --> 00:10:42,970
And so let's fix it.
247
00:10:42,970 --> 00:10:44,803
So how do we fix it?
248
00:10:45,830 --> 00:10:48,890
Well, we simply set the align items property
249
00:10:48,890 --> 00:10:52,016
on the parent to something else.
250
00:10:52,016 --> 00:10:54,560
So on the flex container here,
251
00:10:54,560 --> 00:10:56,280
let's say align
252
00:10:57,850 --> 00:10:58,683
items
253
00:10:58,683 --> 00:11:01,703
and then set it to flex start.
254
00:11:03,430 --> 00:11:05,100
And yeah,
255
00:11:05,100 --> 00:11:07,310
so now it's back to only occupying
256
00:11:07,310 --> 00:11:08,760
vertically the space
257
00:11:08,760 --> 00:11:11,261
that is necessary without growing
258
00:11:11,261 --> 00:11:13,970
as much as it can.
259
00:11:13,970 --> 00:11:16,540
Great. That's amazing.
260
00:11:16,540 --> 00:11:20,120
So with this, we finished applying Flexbox
261
00:11:20,120 --> 00:11:24,160
to our project and in this lecture in particular,
262
00:11:24,160 --> 00:11:26,320
we used almost all of the things
263
00:11:26,320 --> 00:11:29,510
that we had already learned about Flexbox.
264
00:11:29,510 --> 00:11:31,520
So that's amazing and that's
265
00:11:31,520 --> 00:11:33,360
great, great progress.
266
00:11:33,360 --> 00:11:34,440
If you're still sticking
267
00:11:34,440 --> 00:11:37,130
with me here at this point.
268
00:11:37,130 --> 00:11:39,270
And remember that Flexbox
269
00:11:39,270 --> 00:11:41,830
is a lot of stuff to take in
270
00:11:41,830 --> 00:11:44,980
and personally it took me a lot of time
271
00:11:44,980 --> 00:11:47,470
to actually learn all of it.
272
00:11:47,470 --> 00:11:48,830
So it's really not a problem.
273
00:11:48,830 --> 00:11:51,050
If in your head, things are still
274
00:11:51,050 --> 00:11:53,090
confusing at this point.
275
00:11:53,090 --> 00:11:54,180
All you need to do
276
00:11:54,180 --> 00:11:56,510
is to now start practicing Flexbox
277
00:11:56,510 --> 00:11:57,550
on your own.
278
00:11:57,550 --> 00:12:00,440
That is really key to make the materials
279
00:12:00,440 --> 00:12:02,180
stick in your head.
280
00:12:02,180 --> 00:12:03,630
And the first opportunity
281
00:12:03,630 --> 00:12:06,520
for that, is actually the coding challenge
282
00:12:06,520 --> 00:12:09,460
that is coming up in the next lecture.
283
00:12:09,460 --> 00:12:12,913
So hopefully I see you there as soon as you can.
18285
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.