All language subtitles for 055 The flex Property.en_US

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian Download
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:01,530 --> 00:00:05,210 Let's now learn the basics of the flex property, 2 00:00:05,210 --> 00:00:08,370 which is the property that we use in order to actually 3 00:00:08,370 --> 00:00:10,303 size flex items. 4 00:00:11,880 --> 00:00:15,140 And remember how I showed you in the Flexbox property 5 00:00:15,140 --> 00:00:19,620 overview, how the flex property is actually a shorthand 6 00:00:19,620 --> 00:00:24,220 for flex grow, flex shrink and flex basis. 7 00:00:24,220 --> 00:00:26,960 And so let's now talk about each one of these three, 8 00:00:26,960 --> 00:00:28,420 one by one. 9 00:00:28,420 --> 00:00:32,540 And to start, actually, let me write that down here, 10 00:00:32,540 --> 00:00:35,513 because this is really important to keep in mind. 11 00:00:36,650 --> 00:00:38,023 So removing this, 12 00:00:39,050 --> 00:00:41,720 let me just write that here. 13 00:00:41,720 --> 00:00:44,100 And also the default value. 14 00:00:44,100 --> 00:00:47,883 So the default for flex grow is a zero, 15 00:00:49,520 --> 00:00:51,963 for flex shrink, it is one. 16 00:00:53,590 --> 00:00:56,253 And for flex basis, it's auto. 17 00:00:57,840 --> 00:01:01,040 So let's create a comment here, 18 00:01:01,040 --> 00:01:04,780 comment all of this out. Then here I will write 19 00:01:07,170 --> 00:01:08,540 Defaults. 20 00:01:08,540 --> 00:01:09,610 And so like this, 21 00:01:09,610 --> 00:01:13,410 we can keep this here handy to check out this information 22 00:01:13,410 --> 00:01:14,673 in case we need it. 23 00:01:15,860 --> 00:01:19,880 And let's actually now start with flex basis. 24 00:01:19,880 --> 00:01:24,470 So when we want to size flex items, and in particular with a 25 00:01:24,470 --> 00:01:28,690 width, then we usually do not use the width property, 26 00:01:28,690 --> 00:01:31,860 but instead we use flex basis. 27 00:01:31,860 --> 00:01:33,940 So let's say we want these elements to have 28 00:01:33,940 --> 00:01:36,570 a width of 100 pixels. 29 00:01:36,570 --> 00:01:38,800 Then as I said, 30 00:01:38,800 --> 00:01:42,453 we use flex basis and set that to our width. 31 00:01:43,600 --> 00:01:45,470 So let's see. 32 00:01:45,470 --> 00:01:49,450 And what happened here is that now some of these elements 33 00:01:49,450 --> 00:01:52,760 do actually have a width of 100 pixels, 34 00:01:52,760 --> 00:01:56,230 but when the content is larger than 100 pixels, 35 00:01:56,230 --> 00:02:00,073 then the element actually extends to fit that content. 36 00:02:01,140 --> 00:02:06,140 So let's inspect that here, here with the box model, 37 00:02:07,890 --> 00:02:12,793 and actually even this element is not 100 pixels wide. 38 00:02:14,050 --> 00:02:17,490 So let's remove the gap that we have here, to give ourselves 39 00:02:17,490 --> 00:02:18,593 some more space. 40 00:02:20,060 --> 00:02:22,853 Okay. And so that looks a lot better. 41 00:02:23,960 --> 00:02:26,470 So this one is now a hundred pixels. 42 00:02:26,470 --> 00:02:29,613 This one is two. And so is this, and this, 43 00:02:30,630 --> 00:02:33,520 but then "amazing" is 120 pixels, 44 00:02:33,520 --> 00:02:38,350 and "languages" is even bigger at almost 150 pixels. 45 00:02:38,350 --> 00:02:43,090 So what this means is that flex basis is not really rigid. 46 00:02:43,090 --> 00:02:45,940 So it's more like a recommendation that we make to the 47 00:02:45,940 --> 00:02:49,560 browser, but the browser will then, based on the content, 48 00:02:49,560 --> 00:02:51,860 figure out the optimal length. 49 00:02:51,860 --> 00:02:52,890 All right? 50 00:02:52,890 --> 00:02:54,750 And let's see what happens if we actually 51 00:02:54,750 --> 00:02:59,523 make this like, really big, like let's say 200 pixels, 52 00:03:01,060 --> 00:03:04,300 give it a save, and to see this effect a bit better, 53 00:03:04,300 --> 00:03:07,563 let's actually turn off this last element here. 54 00:03:08,580 --> 00:03:10,200 All right. 55 00:03:10,200 --> 00:03:13,770 And so you see that these three elements are the same size. 56 00:03:13,770 --> 00:03:18,700 I think. So "HTML" is 140, 140, 140. 57 00:03:20,360 --> 00:03:23,420 And in fact, all of them are 140 big. 58 00:03:23,420 --> 00:03:27,860 And so that's nowhere near 200 pixels, right? 59 00:03:27,860 --> 00:03:31,550 And the reason for that is that, by default, Flexbox is 60 00:03:31,550 --> 00:03:35,620 allowed to shrink elements so that they fit the container. 61 00:03:35,620 --> 00:03:39,460 And so that's what the flex shrink here set to one 62 00:03:39,460 --> 00:03:41,090 actually means. 63 00:03:41,090 --> 00:03:44,980 So again, if there is not enough space in a container 64 00:03:44,980 --> 00:03:48,820 to fit the items with the size that we described here 65 00:03:48,820 --> 00:03:50,560 using flex basis, 66 00:03:50,560 --> 00:03:54,760 then Flexbox is allowed to shrink these items by default 67 00:03:54,760 --> 00:03:57,693 because flex shrink is set to one. 68 00:03:58,630 --> 00:04:00,803 However, if we want to change that, 69 00:04:01,750 --> 00:04:03,993 which sometimes we might want, 70 00:04:04,920 --> 00:04:07,683 then we can simply set this to zero. 71 00:04:08,900 --> 00:04:13,830 And so now you see that they are indeed 200 pixels wide. 72 00:04:13,830 --> 00:04:18,570 But then of course the content no longer fits the container. 73 00:04:18,570 --> 00:04:20,070 All right? 74 00:04:20,070 --> 00:04:24,400 So setting flex shrink to zero is not always advisable, 75 00:04:24,400 --> 00:04:26,980 but in some situations it's necessary. 76 00:04:26,980 --> 00:04:30,547 And we will actually come across one of those in our big 77 00:04:30,547 --> 00:04:33,770 OmniFood project later in the course. 78 00:04:33,770 --> 00:04:34,603 Okay. 79 00:04:35,820 --> 00:04:39,960 So essentially what flex shrink does is to determine whether 80 00:04:39,960 --> 00:04:44,803 Flexbox is allowed to shrink element if necessary or not. 81 00:04:45,710 --> 00:04:46,543 All right? 82 00:04:46,543 --> 00:04:50,060 And finally, there's also basically the opposite of that, 83 00:04:50,060 --> 00:04:53,850 which is flex grow, and which determines whether elements 84 00:04:53,850 --> 00:04:58,260 are allowed to grow as large as they can or not. 85 00:04:58,260 --> 00:04:59,763 So let's try that. 86 00:05:01,400 --> 00:05:05,923 So let's say flex grow, set to one. 87 00:05:07,250 --> 00:05:10,290 And in this case, it actually doesn't make much sense to 88 00:05:10,290 --> 00:05:12,360 have the flex basis. 89 00:05:12,360 --> 00:05:14,863 But let's just see what happens in this situation. 90 00:05:15,930 --> 00:05:17,920 Well, now nothing changed. 91 00:05:17,920 --> 00:05:20,363 So let's actually turn this one here off. 92 00:05:21,330 --> 00:05:22,640 All right. 93 00:05:22,640 --> 00:05:26,910 And now you see that all of them have exactly the same size 94 00:05:26,910 --> 00:05:31,370 and in total they filled up the entire flex container. 95 00:05:31,370 --> 00:05:35,860 And so that's exactly what flex grow set to one is doing. 96 00:05:35,860 --> 00:05:36,800 Okay? 97 00:05:36,800 --> 00:05:39,430 So if we turned that off right here, 98 00:05:39,430 --> 00:05:42,830 then each of the elements would simply be back to occupying 99 00:05:42,830 --> 00:05:45,800 the width that they need to fit the content. 100 00:05:45,800 --> 00:05:49,720 But again, if we set flex grow here to one, 101 00:05:49,720 --> 00:05:53,960 then all this remaining space right here is basically evenly 102 00:05:53,960 --> 00:05:56,950 divided by all the remaining elements, 103 00:05:56,950 --> 00:06:01,810 because all these elements now have flex grow set to one. 104 00:06:01,810 --> 00:06:03,933 So in this situation right here. 105 00:06:05,250 --> 00:06:06,580 All right. 106 00:06:06,580 --> 00:06:10,450 But what happens if actually only one of these five here 107 00:06:10,450 --> 00:06:12,603 would have flex grow set to one? 108 00:06:13,830 --> 00:06:17,570 Well, let's turn this off permanently. 109 00:06:17,570 --> 00:06:19,780 And then let's try for example, 110 00:06:19,780 --> 00:06:21,860 here in the first element 111 00:06:21,860 --> 00:06:26,860 to set flex grow to one. 112 00:06:28,060 --> 00:06:31,710 So again, first we had flex grow set to one 113 00:06:31,710 --> 00:06:34,420 on all of the elements, right? 114 00:06:34,420 --> 00:06:37,300 So that's why we used here the .el selector, 115 00:06:37,300 --> 00:06:39,410 which are all of these elements. 116 00:06:39,410 --> 00:06:42,970 But now we are setting it only on the very first one. 117 00:06:42,970 --> 00:06:44,970 So what do you think is going to happen? 118 00:06:46,100 --> 00:06:49,480 Well, now only this element here was allowed to 119 00:06:49,480 --> 00:06:52,140 fill up all the remaining space. 120 00:06:52,140 --> 00:06:56,230 And so these four are still with the size of the content, 121 00:06:56,230 --> 00:07:00,253 and then the remaining space was filled up by this element. 122 00:07:01,870 --> 00:07:02,703 All right. 123 00:07:03,670 --> 00:07:08,120 Let's turn it back off here, and back on here 124 00:07:08,120 --> 00:07:11,590 so we can see one other thing. 125 00:07:11,590 --> 00:07:16,140 So, setting flex grow to one on all of these elements here 126 00:07:16,140 --> 00:07:19,090 makes it so that they have the same size. 127 00:07:19,090 --> 00:07:21,330 And it wouldn't even have to be one. 128 00:07:21,330 --> 00:07:24,020 What matters is that they are the same number. 129 00:07:24,020 --> 00:07:26,250 So if all of them would be five, 130 00:07:26,250 --> 00:07:29,170 then they would still have the same size. 131 00:07:29,170 --> 00:07:33,840 Okay? But now if one of them was two. 132 00:07:33,840 --> 00:07:36,990 So let's again, try this one here. 133 00:07:36,990 --> 00:07:40,530 Well, then this one here would get double of the remaining 134 00:07:40,530 --> 00:07:42,993 space than these other ones. 135 00:07:43,890 --> 00:07:45,720 So let's see that. 136 00:07:45,720 --> 00:07:48,460 And so indeed, this now is a bit bigger 137 00:07:48,460 --> 00:07:51,600 than these other ones, right? 138 00:07:51,600 --> 00:07:56,600 So this one has 197 pixels while this one has 108. 139 00:07:57,280 --> 00:08:01,230 So having this value here double the flex grow 140 00:08:01,230 --> 00:08:03,560 of the other ones doesn't mean that 141 00:08:03,560 --> 00:08:07,010 this one here will get double the size. Okay? 142 00:08:07,010 --> 00:08:10,770 What it does mean is that it gets double of the available 143 00:08:10,770 --> 00:08:14,340 empty space than these other four ones. 144 00:08:14,340 --> 00:08:18,550 For example, imagine that the empty space was 600 pixels. 145 00:08:18,550 --> 00:08:23,430 Then this would get 100, and 100, and 100, and 100. 146 00:08:23,430 --> 00:08:25,853 And this one would get 200. 147 00:08:27,380 --> 00:08:30,150 And if we set it to something even bigger, 148 00:08:30,150 --> 00:08:32,610 then it would get an even bigger portion 149 00:08:32,610 --> 00:08:35,900 of the remaining space. Okay. 150 00:08:35,900 --> 00:08:40,820 But actually usually what we do is to simply set flex grow 151 00:08:40,820 --> 00:08:44,190 to one on all of the flex items, 152 00:08:44,190 --> 00:08:47,320 because that's something very usual that we want. 153 00:08:47,320 --> 00:08:50,710 So basically having all the elements expanding 154 00:08:50,710 --> 00:08:53,420 in order to fill the empty space. 155 00:08:53,420 --> 00:08:56,623 And of course there can still be a gap in between. 156 00:08:57,590 --> 00:09:00,040 Let's just use a smaller one 157 00:09:00,040 --> 00:09:03,023 so that we still have some space over. 158 00:09:04,940 --> 00:09:06,380 All right. 159 00:09:06,380 --> 00:09:10,260 And now finally, let's talk about the flex property itself, 160 00:09:10,260 --> 00:09:14,540 which, remember, is a shorthand for these three. 161 00:09:14,540 --> 00:09:17,980 Now the flex property is actually pretty smart. 162 00:09:17,980 --> 00:09:19,440 So for example, 163 00:09:19,440 --> 00:09:23,960 we can simply set it to one like this, and then it will 164 00:09:23,960 --> 00:09:26,410 automatically figure out that this means 165 00:09:26,410 --> 00:09:28,323 that flex grow should be one. 166 00:09:29,280 --> 00:09:30,980 So we don't need this. 167 00:09:30,980 --> 00:09:33,900 And usually we never do it like this. 168 00:09:33,900 --> 00:09:37,110 We always write just "flex" one. 169 00:09:37,110 --> 00:09:39,990 And we then end up with the same result. 170 00:09:39,990 --> 00:09:42,930 So as a best practice, we should in fact, 171 00:09:42,930 --> 00:09:46,180 never use one of these three here individually, 172 00:09:46,180 --> 00:09:48,563 but always use the flex property. 173 00:09:49,560 --> 00:09:50,393 Okay. 174 00:09:51,640 --> 00:09:56,200 So this one here is equivalent to using just this, 175 00:09:56,200 --> 00:09:58,390 but before, for example, 176 00:09:58,390 --> 00:10:01,363 when we had this situation right here, remember, 177 00:10:02,320 --> 00:10:06,120 so this, where the content doesn't even fit. 178 00:10:06,120 --> 00:10:08,490 But if we really wanted to do this, 179 00:10:08,490 --> 00:10:11,943 then we should actually still use the flex property. 180 00:10:13,510 --> 00:10:17,280 So the first value is flex grow, which is zero. 181 00:10:17,280 --> 00:10:19,200 And then we would set that to zero, 182 00:10:19,200 --> 00:10:20,793 because that is the default. 183 00:10:21,740 --> 00:10:25,930 Then the second value is flex shrink, which remember, 184 00:10:25,930 --> 00:10:28,230 here we want it to set to zero. 185 00:10:28,230 --> 00:10:30,200 So we would set that to zero. 186 00:10:30,200 --> 00:10:32,980 And then the last one is flex basis. 187 00:10:32,980 --> 00:10:35,333 So this one we want at 200. 188 00:10:37,650 --> 00:10:41,180 And so that's it. We can then just turn off these two. 189 00:10:41,180 --> 00:10:43,593 And again, the result is exactly the same. 190 00:10:45,340 --> 00:10:46,173 Okay. 191 00:10:46,173 --> 00:10:48,360 So always use the shorthand property 192 00:10:48,360 --> 00:10:52,960 and not one of these three here individually. Okay? 193 00:10:52,960 --> 00:10:56,760 Now this one we don't want, let's just leave this one here 194 00:10:56,760 --> 00:10:59,560 as we finish up this lecture. 195 00:10:59,560 --> 00:11:03,770 Now I know that this is a lot to take in and I'm sure that 196 00:11:03,770 --> 00:11:06,970 it all sounds pretty confusing at this point, 197 00:11:06,970 --> 00:11:09,390 especially this flex property. 198 00:11:09,390 --> 00:11:11,160 It actually took me quite some time 199 00:11:11,160 --> 00:11:13,440 to understand this one myself. 200 00:11:13,440 --> 00:11:16,510 And here, we are really just scratching the surface. 201 00:11:16,510 --> 00:11:19,620 And so I don't really expect you to fully 202 00:11:19,620 --> 00:11:21,490 understand what's going on, 203 00:11:21,490 --> 00:11:24,450 but it was still important to introduce you to this property 204 00:11:24,450 --> 00:11:26,530 at this point, so that we can then 205 00:11:26,530 --> 00:11:28,400 use it in our big project. 206 00:11:28,400 --> 00:11:31,743 And by then it will, of course become a lot clearer. 15431

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.