Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,490 --> 00:00:04,660
Time to practice your new flexbox skills
2
00:00:04,660 --> 00:00:07,803
in coding challenge number two of this section.
3
00:00:09,450 --> 00:00:10,590
And once again,
4
00:00:10,590 --> 00:00:13,600
here I already have the code from the last challenge,
5
00:00:13,600 --> 00:00:17,250
which we will use as a starting point for this one.
6
00:00:17,250 --> 00:00:19,440
And also as always,
7
00:00:19,440 --> 00:00:22,230
you can find the link to this code
8
00:00:22,230 --> 00:00:24,430
somewhere in this lecture.
9
00:00:24,430 --> 00:00:25,770
All right.
10
00:00:25,770 --> 00:00:29,580
So what we're going to do now is to basically replace floats
11
00:00:29,580 --> 00:00:32,410
and do everything with flexbox.
12
00:00:32,410 --> 00:00:37,270
So what I want you to do is to use flexbox here
13
00:00:37,270 --> 00:00:38,820
in this situation.
14
00:00:38,820 --> 00:00:42,460
Also, you can actually now use flexbox here.
15
00:00:42,460 --> 00:00:44,950
So before we were using the trick
16
00:00:44,950 --> 00:00:47,870
of using display as inline block,
17
00:00:47,870 --> 00:00:51,600
but let's actually now change that to flexbox
18
00:00:51,600 --> 00:00:53,860
so that you can practice a bit more.
19
00:00:53,860 --> 00:00:54,920
And then finally,
20
00:00:54,920 --> 00:00:58,600
I want you to build this entire layout here.
21
00:00:58,600 --> 00:01:02,130
So these three elements putting them side-by-side,
22
00:01:02,130 --> 00:01:04,740
using flexbox once again.
23
00:01:04,740 --> 00:01:05,970
And in this case,
24
00:01:05,970 --> 00:01:08,840
I actually don't want you to specify the width
25
00:01:08,840 --> 00:01:11,540
or the flex spaces of...
26
00:01:12,810 --> 00:01:13,973
let's see what it is.
27
00:01:15,530 --> 00:01:17,530
So 243.
28
00:01:17,530 --> 00:01:19,350
So remember that.
29
00:01:19,350 --> 00:01:23,820
So again, right now, I don't want you to specify the width
30
00:01:23,820 --> 00:01:28,190
or the flex spaces of these two columns here manually.
31
00:01:28,190 --> 00:01:30,540
Instead, you should simply allow flexbox
32
00:01:30,540 --> 00:01:34,210
to figure out the width of these two columns.
33
00:01:34,210 --> 00:01:35,360
Okay.
34
00:01:35,360 --> 00:01:37,650
So given everything that you have learned
35
00:01:37,650 --> 00:01:39,570
over the last couple of videos,
36
00:01:39,570 --> 00:01:42,850
I hope that you can have some fun solving this one
37
00:01:42,850 --> 00:01:45,160
and so once you're done with that,
38
00:01:45,160 --> 00:01:46,453
I'll see you back here.
39
00:01:49,070 --> 00:01:50,480
Welcome back
40
00:01:50,480 --> 00:01:54,530
and I hope that you completed this challenge successfully.
41
00:01:54,530 --> 00:01:57,560
And so here is how I would have done it.
42
00:01:57,560 --> 00:01:59,810
So starting here with this price
43
00:01:59,810 --> 00:02:01,980
and the free shipping label,
44
00:02:01,980 --> 00:02:04,350
as always the first question is,
45
00:02:04,350 --> 00:02:07,920
what element should be the flex container?
46
00:02:07,920 --> 00:02:10,393
Well, let's see in our markup here.
47
00:02:11,940 --> 00:02:14,660
So here is the price and the shipping.
48
00:02:14,660 --> 00:02:15,650
And right now,
49
00:02:15,650 --> 00:02:19,910
I think we don't have any suitable flex container, right?
50
00:02:19,910 --> 00:02:22,490
Because we only want these two elements here
51
00:02:22,490 --> 00:02:24,520
to be flex items,
52
00:02:24,520 --> 00:02:26,460
but they do have a lot of siblings
53
00:02:26,460 --> 00:02:30,080
that are also in this same div element here,
54
00:02:30,080 --> 00:02:31,940
so in the same container.
55
00:02:31,940 --> 00:02:34,970
And so what we need to do is to wrap these two
56
00:02:34,970 --> 00:02:37,883
into a new container element,
57
00:02:38,720 --> 00:02:40,900
So div class,
58
00:02:40,900 --> 00:02:44,363
and let's call this one here, the product-price.
59
00:02:50,040 --> 00:02:50,900
Okay.
60
00:02:50,900 --> 00:02:54,463
And then after these two, we will close this.
61
00:03:00,270 --> 00:03:01,103
Okay.
62
00:03:02,150 --> 00:03:04,310
Let's copy our class name here
63
00:03:05,530 --> 00:03:07,763
and then let's use that right here.
64
00:03:10,060 --> 00:03:13,170
So first of all, let's undo the floating stuff here
65
00:03:16,930 --> 00:03:18,450
and this one as well
66
00:03:18,450 --> 00:03:21,990
and also this margin-top that we manually set.
67
00:03:21,990 --> 00:03:23,743
Now, we no longer need to do that.
68
00:03:25,020 --> 00:03:26,570
Right.
69
00:03:26,570 --> 00:03:29,770
And then also we had a clear somewhere...
70
00:03:29,770 --> 00:03:31,490
Ah yeah, right here.
71
00:03:31,490 --> 00:03:34,253
So this one, we also no longer need.
72
00:03:35,190 --> 00:03:38,810
And now this should be quite simple.
73
00:03:38,810 --> 00:03:40,410
So product-price,
74
00:03:40,410 --> 00:03:44,110
which is the element that contains these two here
75
00:03:44,110 --> 00:03:46,203
should not become our flex container.
76
00:03:48,150 --> 00:03:50,370
So display flex,
77
00:03:50,370 --> 00:03:53,750
and immediately they are now side-by-side.
78
00:03:53,750 --> 00:03:58,560
Then we want to push each of them to one of the sides.
79
00:03:58,560 --> 00:03:59,650
Right.
80
00:03:59,650 --> 00:04:00,483
And so for that,
81
00:04:00,483 --> 00:04:03,810
we can use that trick that we also used for the heading
82
00:04:03,810 --> 00:04:07,460
and the navigation in our website header.
83
00:04:07,460 --> 00:04:10,800
And so that was to use justify-content
84
00:04:12,210 --> 00:04:13,060
and then...
85
00:04:14,810 --> 00:04:16,693
Space-between.
86
00:04:18,470 --> 00:04:20,350
And there we go.
87
00:04:20,350 --> 00:04:24,730
And now finally we need to also vertically align these two
88
00:04:24,730 --> 00:04:27,783
because we removed those eight pixels that we had.
89
00:04:28,930 --> 00:04:31,860
And so now, again let's do that automatically
90
00:04:31,860 --> 00:04:36,513
using align-items set to center.
91
00:04:37,520 --> 00:04:40,180
Well, something looks strange here.
92
00:04:40,180 --> 00:04:41,760
Let's inspect that.
93
00:04:41,760 --> 00:04:44,550
Maybe there is some padding or margin...
94
00:04:44,550 --> 00:04:46,800
Ah yeah, indeed it is.
95
00:04:46,800 --> 00:04:51,120
So here the shipping does have some margin at the bottom.
96
00:04:51,120 --> 00:04:55,073
And so if we were to remove that, then it would look normal.
97
00:04:56,250 --> 00:04:57,820
Right.
98
00:04:57,820 --> 00:05:00,830
So now you see, here it makes sense.
99
00:05:00,830 --> 00:05:03,640
And so let's remove that from our code
100
00:05:03,640 --> 00:05:06,183
and put it maybe on this flex container.
101
00:05:09,370 --> 00:05:10,560
So...
102
00:05:11,670 --> 00:05:12,503
Yeah.
103
00:05:12,503 --> 00:05:14,633
So right here, let's remove that from here.
104
00:05:17,170 --> 00:05:18,190
And...
105
00:05:19,430 --> 00:05:20,433
Put that right here.
106
00:05:21,630 --> 00:05:22,510
Okay.
107
00:05:22,510 --> 00:05:23,520
Beautiful.
108
00:05:23,520 --> 00:05:25,620
So now it makes more sense.
109
00:05:25,620 --> 00:05:28,550
And usually we don't run into this kind of problem
110
00:05:28,550 --> 00:05:31,820
because usually, we simply code from scratch
111
00:05:31,820 --> 00:05:34,170
and don't have to deal with the code
112
00:05:34,170 --> 00:05:35,953
that we wrote before at some point.
113
00:05:37,800 --> 00:05:38,700
All right.
114
00:05:38,700 --> 00:05:40,800
Now let's use flexbox on this,
115
00:05:40,800 --> 00:05:42,250
which should be even simpler.
116
00:05:43,780 --> 00:05:44,863
So let's see.
117
00:05:46,360 --> 00:05:48,550
So right here, color.
118
00:05:48,550 --> 00:05:50,150
So color is actually,
119
00:05:50,150 --> 00:05:53,130
I think each of these six elements
120
00:05:53,130 --> 00:05:56,223
and so the flex container should be the parent of those.
121
00:05:57,210 --> 00:05:58,863
So let's see what we have here.
122
00:05:59,750 --> 00:06:01,790
Ah, here we have colors
123
00:06:01,790 --> 00:06:04,590
and let's actually call them product-colors,
124
00:06:04,590 --> 00:06:06,760
so just like all the other elements.
125
00:06:06,760 --> 00:06:09,340
So we have product-price, product-description,
126
00:06:09,340 --> 00:06:10,240
let's call this...
127
00:06:12,300 --> 00:06:13,823
product-colors.
128
00:06:15,860 --> 00:06:17,550
Let's grab that here.
129
00:06:21,203 --> 00:06:25,363
And so to start, let's actually remove this right here.
130
00:06:27,740 --> 00:06:31,440
So they are back to being block elements
131
00:06:31,440 --> 00:06:33,923
and therefore occupying an entire line.
132
00:06:35,070 --> 00:06:39,140
But now we set the parent to flex
133
00:06:39,140 --> 00:06:43,063
and so these are now flex items and they are side-by-side.
134
00:06:44,720 --> 00:06:45,760
All right.
135
00:06:45,760 --> 00:06:47,870
Also we can improve this even more
136
00:06:47,870 --> 00:06:50,430
because now we can remove this margin-right
137
00:06:50,430 --> 00:06:52,190
from each of the elements
138
00:06:52,190 --> 00:06:54,683
and instead use the gap property.
139
00:06:55,840 --> 00:06:57,880
So with that, we then have the definition
140
00:06:57,880 --> 00:07:01,470
of how the layout looks like all in the flex container,
141
00:07:01,470 --> 00:07:04,683
which makes our code a bit easier to reason about.
142
00:07:06,310 --> 00:07:08,100
So 10 pixels.
143
00:07:08,100 --> 00:07:10,180
And there we go.
144
00:07:10,180 --> 00:07:11,090
Great.
145
00:07:11,090 --> 00:07:15,170
Now all we have to do is to apply flexbox also
146
00:07:15,170 --> 00:07:19,293
to this layout, so the layout of these three columns.
147
00:07:20,960 --> 00:07:22,640
So...
148
00:07:22,640 --> 00:07:25,630
Right now each of them has a certain width
149
00:07:25,630 --> 00:07:29,430
that we manually defined and it has float.
150
00:07:29,430 --> 00:07:30,680
Well let's just turn this off
151
00:07:30,680 --> 00:07:34,170
by using command or control slash,
152
00:07:34,170 --> 00:07:35,950
then here I will remove the floats
153
00:07:37,940 --> 00:07:39,913
and the same in this other container,
154
00:07:41,410 --> 00:07:42,950
which...
155
00:07:42,950 --> 00:07:44,530
is called...
156
00:07:45,500 --> 00:07:46,593
product-details.
157
00:07:47,890 --> 00:07:49,853
Let's remove all of that here.
158
00:07:51,160 --> 00:07:53,970
And so now it looks, of course, very weird
159
00:07:53,970 --> 00:07:56,670
and we still have a float on the image.
160
00:07:56,670 --> 00:07:58,563
So let's remove that as well.
161
00:08:01,930 --> 00:08:03,313
Yes, right here.
162
00:08:04,820 --> 00:08:08,980
And so now we lost basically all layout that we had,
163
00:08:08,980 --> 00:08:12,820
but it is of course easy to put that back.
164
00:08:12,820 --> 00:08:16,160
So remember that we created in the last lecture
165
00:08:16,160 --> 00:08:18,470
or actually in the last challenge,
166
00:08:18,470 --> 00:08:21,820
we created this container element, right?
167
00:08:21,820 --> 00:08:23,980
And it is this container here,
168
00:08:23,980 --> 00:08:28,980
which contains both the image and the product-info column,
169
00:08:29,810 --> 00:08:32,950
so this here and also the product-details.
170
00:08:32,950 --> 00:08:37,780
And so this makes sense to be our flex container, right?
171
00:08:37,780 --> 00:08:40,290
So display flex
172
00:08:41,430 --> 00:08:42,470
and...
173
00:08:42,470 --> 00:08:43,303
There we go.
174
00:08:44,280 --> 00:08:47,760
So now these elements are back to being side-by-side
175
00:08:47,760 --> 00:08:49,128
and all we need to do now is
176
00:08:49,128 --> 00:08:52,300
to give these two an equal width.
177
00:08:52,300 --> 00:08:55,340
So again, before we did that manually
178
00:08:55,340 --> 00:08:57,400
by defining this value here.
179
00:08:57,400 --> 00:08:59,650
But now since we're using flexbox,
180
00:08:59,650 --> 00:09:02,020
let's do it in a better way.
181
00:09:02,020 --> 00:09:06,440
And what I'm talking about is to specify flex
182
00:09:06,440 --> 00:09:09,163
and set it to one on this one.
183
00:09:10,840 --> 00:09:13,973
So basically it grows as much as it can,
184
00:09:15,000 --> 00:09:19,480
but this only makes sense once we add the same to the other,
185
00:09:19,480 --> 00:09:20,863
so the product-details.
186
00:09:22,080 --> 00:09:23,303
So let's do that.
187
00:09:25,370 --> 00:09:27,520
So again flex one,
188
00:09:27,520 --> 00:09:30,010
and now since they have the same value,
189
00:09:30,010 --> 00:09:32,890
they should be the exact same size.
190
00:09:32,890 --> 00:09:35,023
And it looks like they are.
191
00:09:36,380 --> 00:09:37,963
Let's inspect that.
192
00:09:38,850 --> 00:09:40,070
And...
193
00:09:42,680 --> 00:09:46,920
so we have the product-info, 243.5,
194
00:09:46,920 --> 00:09:50,920
and this one also 243.5.
195
00:09:50,920 --> 00:09:52,690
So exactly the same,
196
00:09:52,690 --> 00:09:55,310
all thanks to the power of flexbox.
197
00:09:55,310 --> 00:09:57,820
So without us having to go in
198
00:09:57,820 --> 00:10:00,580
and manually calculate these width here,
199
00:10:00,580 --> 00:10:03,860
which, remember, was kind of complicated
200
00:10:03,860 --> 00:10:05,773
and a lot of unnecessary work.
201
00:10:07,450 --> 00:10:08,283
All right.
202
00:10:10,030 --> 00:10:12,520
So this is actually already finished now,
203
00:10:12,520 --> 00:10:14,960
but let's make it even better.
204
00:10:14,960 --> 00:10:18,300
So right now, we are defining these spaces here.
205
00:10:18,300 --> 00:10:22,970
So basically in this one using margins
206
00:10:22,970 --> 00:10:25,890
and we are doing that by setting margin-right
207
00:10:25,890 --> 00:10:30,890
on the product-info and margin-right on the product-image.
208
00:10:31,380 --> 00:10:34,590
But what if at some point we wanted to change that,
209
00:10:34,590 --> 00:10:37,470
then we would have to go search for these properties
210
00:10:37,470 --> 00:10:41,630
in all the elements and change them one by one.
211
00:10:41,630 --> 00:10:43,840
So that's never a good thing to do
212
00:10:43,840 --> 00:10:46,963
and so we can actually remove these from here.
213
00:10:48,230 --> 00:10:49,993
So no more margin-right.
214
00:10:51,510 --> 00:10:52,913
And the same here.
215
00:10:54,450 --> 00:10:58,210
And we can then specify this gap,
216
00:10:58,210 --> 00:11:01,713
so these 40 pixels right on the flex container.
217
00:11:02,720 --> 00:11:06,970
So that's right here using the gap property once again.
218
00:11:06,970 --> 00:11:10,630
And so this is really a lot cleaner and a lot nicer
219
00:11:10,630 --> 00:11:13,450
and a lot easier for us to work with.
220
00:11:13,450 --> 00:11:16,590
Now somehow this looks different.
221
00:11:16,590 --> 00:11:19,363
So let's inspect once again here.
222
00:11:22,540 --> 00:11:25,000
So this column looks smaller somehow.
223
00:11:25,000 --> 00:11:29,073
So let's inspect and indeed it has 223
224
00:11:30,490 --> 00:11:33,483
and this one is also now smaller.
225
00:11:34,550 --> 00:11:36,510
So let's see what happens here.
226
00:11:36,510 --> 00:11:39,210
And one nice trick we can use in the dev tools
227
00:11:39,210 --> 00:11:42,370
to figure out what's going on with flexbox is
228
00:11:42,370 --> 00:11:46,890
to hover the flexbox container and we can even click here
229
00:11:46,890 --> 00:11:51,780
and it will then give us this nice overlay with the gaps
230
00:11:51,780 --> 00:11:56,190
and also with our entire flex container and flex items.
231
00:11:56,190 --> 00:11:58,320
Now what I'm seeing here is
232
00:11:58,320 --> 00:12:01,830
that it created an additional gap here at the end,
233
00:12:01,830 --> 00:12:03,573
where it is not supposed to be.
234
00:12:04,640 --> 00:12:07,250
Now I'm seeing that this is happening
235
00:12:07,250 --> 00:12:10,520
because there is this pseudo element here in the end.
236
00:12:10,520 --> 00:12:14,760
And so therefore, flexbox sees this as an actual element
237
00:12:14,760 --> 00:12:17,250
and therefore adds another gap,
238
00:12:17,250 --> 00:12:20,610
even though in the end, usually we don't want it.
239
00:12:20,610 --> 00:12:25,510
But again right now it is as if this pseudo element here
240
00:12:25,510 --> 00:12:27,800
was actually the last element.
241
00:12:27,800 --> 00:12:31,000
And so therefore, flexbox created another gap
242
00:12:31,000 --> 00:12:32,003
between these two.
243
00:12:33,270 --> 00:12:35,593
So that actually comes again
244
00:12:35,593 --> 00:12:38,820
because of some older legacy code,
245
00:12:38,820 --> 00:12:40,483
which is this clearfix here.
246
00:12:41,370 --> 00:12:46,370
So remember that this clearfix introduces a pseudo element.
247
00:12:46,660 --> 00:12:48,173
So we don't want that.
248
00:12:49,500 --> 00:12:50,610
And...
249
00:12:50,610 --> 00:12:52,560
Yeah, so now that's fixed.
250
00:12:52,560 --> 00:12:53,900
We are back to normal.
251
00:12:53,900 --> 00:12:58,040
And so with that, we are finished with this challenge.
252
00:12:58,040 --> 00:13:00,230
And actually, we are also finished
253
00:13:00,230 --> 00:13:03,803
with this introductory part to flexbox.
254
00:13:04,700 --> 00:13:09,430
So moving on, we will start talking about CSS Grid.
255
00:13:09,430 --> 00:13:11,000
But before you go there,
256
00:13:11,000 --> 00:13:15,280
please make sure that you really, really understood flexbox
257
00:13:15,280 --> 00:13:18,320
or at least these properties that I showed you
258
00:13:18,320 --> 00:13:20,930
in these couple of lectures.
259
00:13:20,930 --> 00:13:24,130
So if you are still really confused about flexbox,
260
00:13:24,130 --> 00:13:27,050
you should not move on to CSS Grid
261
00:13:27,050 --> 00:13:30,430
because then you will get even more confused.
262
00:13:30,430 --> 00:13:33,020
Because they are a bit similar in a way,
263
00:13:33,020 --> 00:13:34,610
so this will confuse you a lot
264
00:13:34,610 --> 00:13:38,990
if you don't have the fundamentals of flexbox down yet.
265
00:13:38,990 --> 00:13:40,980
So if that is the case,
266
00:13:40,980 --> 00:13:44,660
then please try to come up with some own projects
267
00:13:44,660 --> 00:13:46,940
and write some code on your own
268
00:13:46,940 --> 00:13:50,400
to keep practicing these concepts.
269
00:13:50,400 --> 00:13:53,640
I really can't stress enough how important it is
270
00:13:53,640 --> 00:13:54,870
to not just move on
271
00:13:54,870 --> 00:13:59,320
without fully understanding these fundamentals of flexbox.
272
00:13:59,320 --> 00:14:00,530
Okay.
273
00:14:00,530 --> 00:14:02,380
So I hope that made sense.
274
00:14:02,380 --> 00:14:06,830
And then once you are actually ready for your next step,
275
00:14:06,830 --> 00:14:11,433
then let's move on to the CSS Grid part of this section.
19148
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.