All language subtitles for 005 Combining Selectors_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
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
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,620 --> 00:00:04,210 Let's now make the CSS code 2 00:00:04,210 --> 00:00:06,810 that we just wrote a little bit better 3 00:00:06,810 --> 00:00:09,683 by combining some of the selectors. 4 00:00:11,150 --> 00:00:12,950 So you might've noticed 5 00:00:12,950 --> 00:00:15,960 that we applied the exact same font family 6 00:00:15,960 --> 00:00:19,620 to all of our elements here, right? 7 00:00:19,620 --> 00:00:24,320 So all these six CSS rules that we have here, 8 00:00:24,320 --> 00:00:26,830 all of them have font-style, 9 00:00:26,830 --> 00:00:31,103 or actually have font-family set to sans-serif. 10 00:00:32,509 --> 00:00:35,700 And you see that VS Code actually highlights 11 00:00:35,700 --> 00:00:38,543 these occurrences here in all of the rules. 12 00:00:39,410 --> 00:00:43,470 So doing that is a little bit repetitive, right? 13 00:00:43,470 --> 00:00:45,940 And it's also not a good practice 14 00:00:45,940 --> 00:00:48,490 because let's say that all of a sudden 15 00:00:48,490 --> 00:00:52,530 we wanted to change the font-family to something else. 16 00:00:52,530 --> 00:00:54,320 Then we would have to go through all 17 00:00:54,320 --> 00:00:58,250 of these different rules and set the font-family then 18 00:00:58,250 --> 00:01:00,200 to something else there. 19 00:01:00,200 --> 00:01:01,320 So instead, 20 00:01:01,320 --> 00:01:05,980 what we can do is to create a list of selectors 21 00:01:05,980 --> 00:01:08,390 in order to select multiple elements 22 00:01:08,390 --> 00:01:13,143 and then apply this font-family to that list, essentially. 23 00:01:14,920 --> 00:01:17,170 So let me show you how we can do that 24 00:01:17,170 --> 00:01:19,770 and let's do it first here, actually. 25 00:01:19,770 --> 00:01:23,950 So what we want to do is to select the h1 element 26 00:01:23,950 --> 00:01:26,090 and the h2 element 27 00:01:26,090 --> 00:01:28,360 and the h3 element. 28 00:01:28,360 --> 00:01:31,410 And so as you see, the way we write that 29 00:01:31,410 --> 00:01:33,423 is by using these commas. 30 00:01:34,410 --> 00:01:35,243 Okay? 31 00:01:36,100 --> 00:01:37,280 So again, 32 00:01:37,280 --> 00:01:40,330 here, we are going to select the h1 elements 33 00:01:40,330 --> 00:01:44,880 and the h2 elements and the h3 elements 34 00:01:44,880 --> 00:01:46,980 and the h4 elements 35 00:01:46,980 --> 00:01:48,620 and the ps, 36 00:01:48,620 --> 00:01:53,133 and also all the li elements. 37 00:01:55,770 --> 00:01:56,770 Okay. 38 00:01:56,770 --> 00:02:00,910 And now we can grab this text here and cut it 39 00:02:02,000 --> 00:02:03,133 and paste it here. 40 00:02:04,140 --> 00:02:08,683 And now we can remove it from all of these other selectors. 41 00:02:13,150 --> 00:02:14,110 All right. 42 00:02:14,110 --> 00:02:16,150 And if I give it a save now, 43 00:02:16,150 --> 00:02:19,093 the page should basically look exactly the same. 44 00:02:20,180 --> 00:02:21,053 And it does. 45 00:02:22,380 --> 00:02:27,380 Okay, now Prettier formatted our CSS code here like this, 46 00:02:27,610 --> 00:02:30,440 so having one element for each line, 47 00:02:30,440 --> 00:02:32,240 and so this is a bit easier to read. 48 00:02:33,680 --> 00:02:36,980 And so now, if we wanted to change the font-family, 49 00:02:36,980 --> 00:02:41,330 let's say to serif, which is actually the default. 50 00:02:41,330 --> 00:02:43,300 So if I save this now, 51 00:02:43,300 --> 00:02:46,963 then you see that all of the elements changed at once. 52 00:02:48,861 --> 00:02:52,300 So all of them now have the serif text. 53 00:02:52,300 --> 00:02:55,060 Then of course, if we set it back here, 54 00:02:55,060 --> 00:02:58,430 then all of them will change, right? 55 00:02:58,430 --> 00:03:00,973 So now we have serif text everywhere. 56 00:03:02,360 --> 00:03:05,640 Well, actually, except for in the footer. 57 00:03:05,640 --> 00:03:08,610 So that's something that we need to fix. 58 00:03:08,610 --> 00:03:11,170 And to make it easier here, 59 00:03:11,170 --> 00:03:14,380 let's actually simply wrap this text here 60 00:03:15,280 --> 00:03:18,000 inside a paragraph. 61 00:03:18,000 --> 00:03:20,520 So let's come here to our HTML. 62 00:03:20,520 --> 00:03:22,770 So this is really important that you do this. 63 00:03:24,753 --> 00:03:27,173 And so create a new element here 64 00:03:28,870 --> 00:03:30,980 and it automatically closed it. 65 00:03:30,980 --> 00:03:35,603 So let's just then grab this text and paste it here. 66 00:03:36,890 --> 00:03:39,250 And you see that now this paragraph looks 67 00:03:39,250 --> 00:03:40,763 just like all the others. 68 00:03:42,460 --> 00:03:44,580 Okay? So don't skip this step. 69 00:03:44,580 --> 00:03:47,280 Please do this because we will now need it 70 00:03:47,280 --> 00:03:49,300 for another example. 71 00:03:49,300 --> 00:03:53,003 And in fact, let's look at that example right away. 72 00:03:54,130 --> 00:03:59,130 So the size of our paragraphs is 22 pixels. 73 00:03:59,200 --> 00:04:02,530 And so of course, now the paragraph that's in the footer, 74 00:04:02,530 --> 00:04:05,710 so this one, is also 22 pixels. 75 00:04:05,710 --> 00:04:08,190 However, the text that's in the footer 76 00:04:08,190 --> 00:04:11,880 is usually a lot smaller than the rest of the text 77 00:04:11,880 --> 00:04:15,040 because this is just some secondary information 78 00:04:15,040 --> 00:04:16,850 that is not really important. 79 00:04:16,850 --> 00:04:19,800 And so therefore we should actually make this text 80 00:04:19,800 --> 00:04:23,170 in this paragraph here smaller than the text 81 00:04:23,170 --> 00:04:25,100 in the other paragraphs. 82 00:04:25,100 --> 00:04:30,060 And one way in which we can do this is to combine selectors 83 00:04:30,060 --> 00:04:31,083 in another way. 84 00:04:32,740 --> 00:04:37,100 So just to recap, here we combined these six selectors 85 00:04:37,100 --> 00:04:38,630 into one list. 86 00:04:38,630 --> 00:04:43,630 So we say that the selector here is now a list selector. 87 00:04:43,640 --> 00:04:46,660 So this here is still one selector, 88 00:04:46,660 --> 00:04:49,610 but it is a list selector, okay? 89 00:04:49,610 --> 00:04:52,460 So this is one way of combining selectors, 90 00:04:52,460 --> 00:04:56,700 but now I will give you another way of combining selectors 91 00:04:56,700 --> 00:05:00,150 and the goal of that is, as we just discussed, 92 00:05:00,150 --> 00:05:02,323 to decrease the font size in here. 93 00:05:03,400 --> 00:05:06,990 So we will now use the so-called descendant selector, 94 00:05:06,990 --> 00:05:09,473 which is to write something like this. 95 00:05:10,580 --> 00:05:13,390 So we select the footer element, 96 00:05:13,390 --> 00:05:18,190 then a space, and then the p selector. 97 00:05:18,190 --> 00:05:19,770 And so what this will do 98 00:05:19,770 --> 00:05:22,510 is it will select all the p elements 99 00:05:22,510 --> 00:05:26,270 that are inside of footer elements. 100 00:05:26,270 --> 00:05:29,540 And so that's why this is called the descendant selector. 101 00:05:29,540 --> 00:05:32,500 Because the p element is a child element 102 00:05:32,500 --> 00:05:35,040 of the footer in our HTML. 103 00:05:35,040 --> 00:05:37,580 And so therefore, this selector here 104 00:05:37,580 --> 00:05:40,080 will then select all of these paragraphs 105 00:05:40,080 --> 00:05:43,370 that are children of footer elements. 106 00:05:43,370 --> 00:05:45,800 And so if we now set the font size here 107 00:05:45,800 --> 00:05:47,113 to something smaller, 108 00:05:48,210 --> 00:05:50,653 let's say 16 pixels, 109 00:05:52,220 --> 00:05:56,670 then you see that all the other ps, they are still normal, 110 00:05:56,670 --> 00:06:00,630 but in fact, this paragraph that is inside the footer 111 00:06:01,699 --> 00:06:04,680 is now only 16 pixels small. 112 00:06:04,680 --> 00:06:08,040 And hopefully you can see how useful 113 00:06:08,040 --> 00:06:10,820 the descendant selector, like this here, is. 114 00:06:10,820 --> 00:06:13,760 So actually use this all the time. 115 00:06:13,760 --> 00:06:18,220 However, in this case, this actually isn't very robust 116 00:06:18,220 --> 00:06:20,410 because, like this, 117 00:06:20,410 --> 00:06:24,130 the selector basically reflects the HTML structure, 118 00:06:24,130 --> 00:06:26,470 which can lead to problems. 119 00:06:26,470 --> 00:06:28,110 And to show that to you, 120 00:06:28,110 --> 00:06:31,020 let's write another descendant selector. 121 00:06:31,020 --> 00:06:31,860 So in this case, 122 00:06:31,860 --> 00:06:35,650 let's say that we want to select this paragraph here 123 00:06:35,650 --> 00:06:37,233 that's inside of the header. 124 00:06:38,520 --> 00:06:41,793 So remember that we have a header here in the article, 125 00:06:43,730 --> 00:06:46,023 so this one here, and we have a p. 126 00:06:46,960 --> 00:06:50,500 So let's say we wanted to style that italic, 127 00:06:50,500 --> 00:06:52,330 so make the text italic. 128 00:06:52,330 --> 00:06:57,330 And so using what we just learned, we could say header, 129 00:06:57,796 --> 00:07:00,623 and then the p that is inside there, 130 00:07:03,260 --> 00:07:07,923 and then say font-style and set it to italic. 131 00:07:09,380 --> 00:07:13,050 Okay, so this worked just fine. 132 00:07:13,050 --> 00:07:15,110 But now imagine that, for some reason, 133 00:07:15,110 --> 00:07:18,920 we also added a paragraph to this header element 134 00:07:18,920 --> 00:07:20,383 that is up here in the page. 135 00:07:21,810 --> 00:07:23,560 So let's try that. 136 00:07:23,560 --> 00:07:27,950 And remember that here we have another header, right? 137 00:07:27,950 --> 00:07:31,623 So as I was just saying, let's add a p here, 138 00:07:32,670 --> 00:07:35,053 Test paragraph, 139 00:07:36,040 --> 00:07:39,960 and you see that this one is now also italic. 140 00:07:39,960 --> 00:07:43,450 However, what we wanted was only this paragraph here 141 00:07:43,450 --> 00:07:48,450 to be italic and not this one, right? 142 00:07:48,480 --> 00:07:51,070 So we need to solve this somehow. 143 00:07:51,070 --> 00:07:53,130 And actually we can solve it. 144 00:07:53,130 --> 00:07:54,403 It is not too hard. 145 00:07:55,240 --> 00:07:56,900 Well, at least in this case, 146 00:07:56,900 --> 00:08:01,900 because this header here is inside of the article 147 00:08:01,920 --> 00:08:05,000 and this one is not, right? 148 00:08:05,000 --> 00:08:10,000 And so we can actually create a nested descendant selector. 149 00:08:10,100 --> 00:08:14,270 So we can have a descendant inside a descendant. 150 00:08:14,270 --> 00:08:16,573 So what I mean is basically writing this. 151 00:08:17,520 --> 00:08:21,740 So we only want the paragraphs that are inside of headers, 152 00:08:21,740 --> 00:08:26,150 which are inside of articles, to be italic. 153 00:08:26,150 --> 00:08:27,690 So let's give it a save. 154 00:08:27,690 --> 00:08:29,780 And now only this one is italic 155 00:08:29,780 --> 00:08:32,159 and this one here, not anymore. 156 00:08:32,159 --> 00:08:33,980 So this actually works, 157 00:08:33,980 --> 00:08:38,250 but we are now even more encoding the HTML structure 158 00:08:38,250 --> 00:08:40,720 into our CSS selectors, 159 00:08:40,720 --> 00:08:44,650 and that can make our code hard to maintain in the future 160 00:08:44,650 --> 00:08:47,070 if we ever change our HTML. 161 00:08:47,070 --> 00:08:49,230 And so that's not a good idea. 162 00:08:49,230 --> 00:08:51,230 So if we think about this, 163 00:08:51,230 --> 00:08:55,240 wouldn't it actually be a lot better if we had a way 164 00:08:55,240 --> 00:08:58,400 to basically give some elements names 165 00:08:58,400 --> 00:09:01,183 and then use these names to select them? 166 00:09:02,040 --> 00:09:04,450 Well, we actually can do that, 167 00:09:04,450 --> 00:09:08,470 and it is exactly the subject of the next lecture. 168 00:09:08,470 --> 00:09:10,473 So let's go there right now. 12106

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