All language subtitles for 001 The Cascade - Specificity and Inheritance_en

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 Download
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:00,080 --> 00:00:00,680 Hey, guys. 2 00:00:00,680 --> 00:00:06,380 Today we're going to learn all about the CSS Cascade and you're going to understand why it's actually 3 00:00:06,380 --> 00:00:10,880 called a Cascading Style Sheet after completing this lesson. 4 00:00:11,090 --> 00:00:17,600 So what exactly is the meaning of the cascading part of the cascading style sheet? 5 00:00:17,690 --> 00:00:25,600 Well, it's really only relevant when we think about multiple different conflicting CSS rules. 6 00:00:25,610 --> 00:00:33,500 So if you have different rules that target the same element, for example, an h1, then we have to 7 00:00:33,500 --> 00:00:38,210 determine which one is higher up in the hierarchy. 8 00:00:38,390 --> 00:00:45,680 And this method of working out which of the rules actually get applied and which ones get ignored is 9 00:00:45,680 --> 00:00:48,350 how our cascade comes to be. 10 00:00:48,470 --> 00:00:55,520 Imagine if you have a cascade where there is a pool at the top and then there is another one at the 11 00:00:55,520 --> 00:00:56,360 bottom. 12 00:00:56,450 --> 00:01:03,250 If we think about how the rule gets applied, then the browser is going to look at the water level. 13 00:01:03,270 --> 00:01:11,970 Imagine if this rule gets applied first, and then as the water falls down the cascade, it sees another 14 00:01:11,970 --> 00:01:14,760 rule that's applying to the same element. 15 00:01:14,790 --> 00:01:19,440 Then you will see this style, number one being applied. 16 00:01:19,740 --> 00:01:26,940 So multiple styles can be applied to the same thing, but because of the order of importance, the one 17 00:01:26,940 --> 00:01:33,510 that is the most important once you've finished the cascade is the one the user actually sees on screen. 18 00:01:34,110 --> 00:01:35,640 Here's an example. 19 00:01:35,790 --> 00:01:45,450 Let's say we've got an ordered list which has three list items, and then in our styles.css we set all 20 00:01:45,450 --> 00:01:48,540 of the list items to have a green color. 21 00:01:48,750 --> 00:01:53,520 Now, once you run the code at this point, everything is going to turn green. 22 00:01:53,520 --> 00:02:00,420 And now we have a list of three ordered list items, all with green text. 23 00:02:00,720 --> 00:02:09,810 Now, however, if one of those list items happened to have an inline style where we've got the style 24 00:02:09,810 --> 00:02:17,550 attribute being set and we set it to a different color in this case, red, what do you think will happen 25 00:02:17,550 --> 00:02:19,710 when we run this updated code? 26 00:02:19,920 --> 00:02:23,250 Well, that is where our cascade comes in. 27 00:02:23,580 --> 00:02:30,000 The first level of applying style comes from the external stylesheet, and then it's going to look to 28 00:02:30,000 --> 00:02:37,560 see, well, maybe there are internal styles being applied via the style tag, and if there aren't any, 29 00:02:37,590 --> 00:02:43,890 then it's going to look at the next level and see that, "Oh, are there any inline styles being applied?" 30 00:02:43,890 --> 00:02:50,220 And this is the final style that gets applied to this particular list item. 31 00:02:50,340 --> 00:02:54,720 And so in the end we end up with everything being green. 32 00:02:54,720 --> 00:03:02,610 But then in the last minute this one gets changed to red because of the way the Cascade works. 33 00:03:02,640 --> 00:03:09,150 There are four broad categories which we look at when we're determining the overall level of importance 34 00:03:09,150 --> 00:03:11,010 of a CSS rule, 35 00:03:11,010 --> 00:03:16,590 and these categories are Position, Specificity, Type and importance. 36 00:03:16,590 --> 00:03:19,920 And I'm going to go through each of these with a code example. 37 00:03:19,950 --> 00:03:29,400 The first thing we look at at the very top of the cascade is whether if a rule is at a higher or lower 38 00:03:29,400 --> 00:03:33,840 position in the CSS relative to other rules. 39 00:03:33,960 --> 00:03:40,290 Notice here I've got two rules applying to the same thing and setting the same property. 40 00:03:40,320 --> 00:03:44,850 I'm trying to set the color of the text red, but I'm also trying to set it blue. 41 00:03:44,880 --> 00:03:47,280 Well, in fact they both happen. 42 00:03:47,280 --> 00:03:51,590 But the one that is lower down simply replaces the previous one. 43 00:03:51,600 --> 00:03:55,190 So first it becomes red and then immediately becomes blue. 44 00:03:55,200 --> 00:03:59,010 So this is what you're going to see on screen. 45 00:03:59,400 --> 00:04:09,030 The position of a CSS rule can apply to the position within the curly braces of a selector, but it 46 00:04:09,030 --> 00:04:14,610 could also be that you target the same element lower down in this. 47 00:04:14,610 --> 00:04:21,630 So I could target the li again down here and I could set the color to green. 48 00:04:21,930 --> 00:04:27,660 And in this case, because this is even lower down than these two positions. 49 00:04:27,660 --> 00:04:35,220 So this is one, two and three, then this one is going to be the final one that will see. The lower 50 00:04:35,220 --> 00:04:41,640 down in a CSS external file or in an internal style element 51 00:04:41,670 --> 00:04:50,010 the more important it is. If we're looking at this cascade, a rule that gets applied here will then 52 00:04:50,040 --> 00:04:55,100 be replaced by a rule that gets applied here and finally here. 53 00:04:55,110 --> 00:04:59,820 So the lower down the file, the rule is, the more 54 00:04:59,920 --> 00:05:05,680 more important, it is. Now the next category is the Specificity. 55 00:05:05,680 --> 00:05:14,770 And CSS specificity refers to how specific a selector is in terms of the elements that you're applying the 56 00:05:14,770 --> 00:05:16,060 CSS rule to. 57 00:05:16,300 --> 00:05:27,250 As an example, let's say we create a list item element and we give it an ID that's equal to " first-id", 58 00:05:28,060 --> 00:05:33,760 and then we give it a class that's equal to "first-class," 59 00:05:33,970 --> 00:05:39,130 and then finally we give it the attribute of "draggable" as well. 60 00:05:41,810 --> 00:05:46,370 And this is our opening tag for our list item element. 61 00:05:47,570 --> 00:05:54,980 Now, if we look at this element and we think about the different ways that we can target this element, 62 00:05:55,010 --> 00:06:00,520 then these four CSS rules will all target this particular element, 63 00:06:00,530 --> 00:06:05,450 but they have different Specificity and they're listed in order. 64 00:06:05,630 --> 00:06:13,670 The first one selects all the list-item elements, so there could be many other list-item elements in 65 00:06:13,670 --> 00:06:15,020 our HTML file. 66 00:06:15,020 --> 00:06:17,770 So this is the least specific. 67 00:06:17,780 --> 00:06:19,940 It's the element selector. 68 00:06:20,450 --> 00:06:25,850 The next level of Specificity is the class selector. 69 00:06:25,850 --> 00:06:33,470 Remember, the class selector starts with a dot (.) and this will select all the other list elements that 70 00:06:33,470 --> 00:06:36,800 have this class name, "first-class". 71 00:06:36,980 --> 00:06:45,290 And because we can have multiple different elements with the same class for this reason it is more specific 72 00:06:45,290 --> 00:06:49,920 than element, but it's also not the most specific way of selecting an element. 73 00:06:50,520 --> 00:06:58,260 The next one is selecting an attribute. Even though most sources will tell you that attribute and class 74 00:06:58,260 --> 00:07:02,370 are actually the same level of specificity if you try it out, 75 00:07:02,370 --> 00:07:06,060 in most cases, the attribute will override the class. 76 00:07:06,540 --> 00:07:15,300 In this case, we're selecting on this attribute of "draggable" and we're turning the list-item that has 77 00:07:15,300 --> 00:07:18,000 that attribute set to the color of purple. 78 00:07:18,000 --> 00:07:23,400 And at this point of our code, if we didn't go any further, our text would look purple. 79 00:07:23,670 --> 00:07:32,310 So the final level of Specificity and the most specific is the ID selector, which is denoted by the 80 00:07:32,310 --> 00:07:34,440 pound sign or the hashtag sign (#). 81 00:07:34,590 --> 00:07:42,720 And this is the most specific because theoretically on a single web page you should only have one particular 82 00:07:42,720 --> 00:07:43,950 ID name. 83 00:07:43,950 --> 00:07:48,840 So it essentially targets only one element on the page. 84 00:07:48,840 --> 00:07:55,830 So the order of specificity is ID, attribute, class and element. 85 00:07:55,860 --> 00:08:02,910 If we think about our cascade starting up here, firstly we look to see if there are any element selectors 86 00:08:02,910 --> 00:08:05,220 that target a particular element, 87 00:08:05,250 --> 00:08:11,790 then we look at class, then we look at attribute and finally we look at ID, and if we applied the 88 00:08:11,790 --> 00:08:18,030 CSS rules in this order, then the final one will be the one that will be applied. 89 00:08:18,030 --> 00:08:24,750 So if all of these rules were applied to this particular element, then finally what we would see is 90 00:08:24,750 --> 00:08:27,240 the text would be orange. 91 00:08:28,260 --> 00:08:31,170 Now the next category is the type. 92 00:08:31,200 --> 00:08:37,289 We know that there are three different ways that we can apply CSS to a particular file. 93 00:08:37,289 --> 00:08:47,100 We can use the external stylesheet which is done using the link element, linking to a particular file 94 00:08:47,100 --> 00:08:48,690 in our project folder. 95 00:08:48,900 --> 00:08:57,120 Then there is internal CSS, which is done through the style element and putting the CSS in between 96 00:08:57,120 --> 00:09:01,230 the open and closing brackets of the style element. 97 00:09:01,230 --> 00:09:10,410 And finally there is the inline style where the CSS is applied through the style attribute inside the 98 00:09:10,410 --> 00:09:13,950 opening tag of an actual HTML element. 99 00:09:14,250 --> 00:09:22,050 In terms of the cascade, the most important are the styles that are applied in line because this targets 100 00:09:22,050 --> 00:09:24,510 only one specific element. 101 00:09:24,510 --> 00:09:26,420 It's just this h1. 102 00:09:26,430 --> 00:09:29,370 It doesn't matter if you have ten other h1's. 103 00:09:29,400 --> 00:09:33,780 This style is only going to be applied to this particular element. 104 00:09:34,380 --> 00:09:43,740 The next one is the internal, because the internal stylesheet only exists inside one web page, whereas 105 00:09:43,740 --> 00:09:48,920 the external stylesheet can actually be applied across many different HTML files 106 00:09:48,920 --> 00:09:56,210 as long as you all link to the same CSS file. In this order of our cascade, 107 00:09:56,210 --> 00:10:01,100 first, we check if there are any styles relevant from the external stylesheet, 108 00:10:01,130 --> 00:10:06,920 then we check whether if there are any from the internal stylesheet, and finally if there are any inline 109 00:10:06,920 --> 00:10:07,610 styles. 110 00:10:07,610 --> 00:10:14,630 So then going down the cascade, this is the order where the CSS will get applied. 111 00:10:15,340 --> 00:10:18,070 If you had the same thing, 112 00:10:18,070 --> 00:10:23,040 so targeting the h1, setting its color here, here and here, 113 00:10:23,050 --> 00:10:28,960 if they all target the same element and they're all trying to change the same property, say the text 114 00:10:28,960 --> 00:10:35,410 color, then this is going to be the one that will be shown on screen after you cascade through the 115 00:10:35,410 --> 00:10:36,790 different levels. 116 00:10:37,750 --> 00:10:46,810 The final thing, which is a keyword that you can apply to any CSS rule, is the "important" keyword. 117 00:10:47,020 --> 00:10:55,930 So you could have a color property set and we know how we set it normally by simply adding a value after 118 00:10:55,930 --> 00:10:56,880 the property, 119 00:10:56,890 --> 00:11:05,380 but if you add a space and then you add this keyword, exclamation mark and then the important word (!important), 120 00:11:05,410 --> 00:11:12,520 then this is going to ensure that this is going to be the most important rule relative to that element. 121 00:11:12,550 --> 00:11:19,550 It doesn't matter how important this previous rule is, it could have been inline or it could have been 122 00:11:19,550 --> 00:11:24,290 in an ID selector, or it could have been at the very bottom of the page. 123 00:11:24,290 --> 00:11:31,010 This rule is going to come out as the Top Trump. If you haven't already, I recommend taking notes of 124 00:11:31,010 --> 00:11:37,850 this page because you can actually use this as a very handy way of working out why your CSS is not working 125 00:11:37,850 --> 00:11:45,740 or when you're trying to do something specific and you're trying to make sure that a CSS rule gets applied. 126 00:11:46,220 --> 00:11:51,650 You can work your way from the top of the cascade all the way down. 127 00:11:51,650 --> 00:11:56,990 And there is, obviously the higher level, which is the categories, position, specificity, type and 128 00:11:56,990 --> 00:11:57,860 importance. 129 00:11:57,860 --> 00:12:03,920 And then within each cascade you can imagine there's almost a mini-cascade level where you determine 130 00:12:03,920 --> 00:12:06,230 which one is most important. 131 00:12:06,440 --> 00:12:11,870 Now we're going to try out some quizzes to enforce these rules, and I recommend taking a photo of this 132 00:12:11,870 --> 00:12:17,870 page and having it side by side while you do the quiz, because remember, we're programmers. 133 00:12:17,870 --> 00:12:19,760 We're not here to memorize things. 134 00:12:19,760 --> 00:12:22,250 You can always look at this page when needed. 135 00:12:22,670 --> 00:12:24,980 This is the first quiz, 136 00:12:25,070 --> 00:12:34,220 here we have an h1 element, and it's got a class as well as an ID, and there are two different 137 00:12:34,220 --> 00:12:39,440 CSS rules and you can assume that they are both on an external style sheet, 138 00:12:39,440 --> 00:12:41,900 so our style.css. 139 00:12:42,140 --> 00:12:47,060 Now I want you to pick what will be the final color of this h1? 140 00:12:47,060 --> 00:12:51,500 Will it be blue or will it be green? 141 00:12:52,070 --> 00:13:00,680 And once you've made your selection, go ahead and use your QR code reader to scan the QR code that 142 00:13:00,680 --> 00:13:05,240 corresponds to your answer, blue or green, 143 00:13:05,240 --> 00:13:11,450 and then you will see a gif to tell you whether you got it right or wrong. 144 00:13:11,690 --> 00:13:16,370 So you have 30s starting now (Background music). 145 00:13:45,180 --> 00:13:45,540 All right. 146 00:13:45,540 --> 00:13:47,040 So did you get it right? 147 00:13:47,160 --> 00:13:56,730 So in this case, we have a specificity battle because this is a class selector and this is an ID selector. 148 00:13:56,730 --> 00:14:02,370 When we're looking at the specificity, the most specific always wins. 149 00:14:02,370 --> 00:14:07,500 So in this case, the ID will trump the class. 150 00:14:08,170 --> 00:14:14,500 And that's why if this code was run, which you can test out yourself, the color of the text will be 151 00:14:14,500 --> 00:14:15,280 green. 152 00:14:15,290 --> 00:14:18,280 So this was the correct answer. 153 00:14:18,310 --> 00:14:19,560 Did you get that right? 154 00:14:19,570 --> 00:14:20,740 If not, don't worry. 155 00:14:20,740 --> 00:14:22,690 We've got more questions coming up. 156 00:14:23,350 --> 00:14:26,110 This is our next quiz question. 157 00:14:26,290 --> 00:14:36,310 Again, we've got an h1 element, but notice this time it's got two classes applied "a-class" and "another- 158 00:14:36,310 --> 00:14:37,090 class." 159 00:14:37,210 --> 00:14:42,760 You can apply multiple classes to the same element as long as you add a space in between them. 160 00:14:42,940 --> 00:14:48,010 Now, your job is to determine what is the final color of this h1. 161 00:14:48,040 --> 00:14:53,170 Is it going to be blue or is it going to be green? 162 00:14:54,190 --> 00:14:57,070 You have 30s starting now. (Background music) 163 00:15:26,810 --> 00:15:35,120 In this case, what's relevant is the position of CSS rule, because notice that they both have the 164 00:15:35,120 --> 00:15:36,950 same specificity. 165 00:15:36,980 --> 00:15:40,760 This is a class selector, and this is also a class selector, 166 00:15:40,760 --> 00:15:48,410 and they both select the same element, right here. And we're assuming that they're in the same file, 167 00:15:48,410 --> 00:15:53,240 so no difference in terms of external, internal or inline. 168 00:15:53,240 --> 00:15:59,660 So then the only thing that matters is the order where they appear in the file. 169 00:15:59,780 --> 00:16:06,020 So remember that the cascade goes from the top to the bottom and the ones at the bottom will be the 170 00:16:06,020 --> 00:16:08,150 ones that replace the ones at the top. 171 00:16:08,240 --> 00:16:17,630 So in this case, the final color of the h1 will be blue. When all other things are equal, for example, 172 00:16:17,630 --> 00:16:19,760 Specificity, Type and Importance. 173 00:16:19,790 --> 00:16:24,350 Then we look at a specific category and see which one comes out trumps. 174 00:16:25,120 --> 00:16:27,580 Here's the final quiz question for today. 175 00:16:28,060 --> 00:16:36,110 Here we have an HTML file and I want you to figure out what will be the final color of the h1. 176 00:16:36,130 --> 00:16:39,850 Will it be blue or will it be green? 177 00:16:40,240 --> 00:16:43,900 You have 30s clock starts now. (Background music) 178 00:17:13,940 --> 00:17:14,300 All right. 179 00:17:14,300 --> 00:17:24,530 So in this case, what we've got is an ID called "an-id", and we have an inline style being applied. 180 00:17:24,560 --> 00:17:32,330 So remember, in terms of specificity, ID selectors are the most important. 181 00:17:32,510 --> 00:17:43,880 However, the CSS specificity as a category is not as important as the type of CSS being applied. 182 00:17:44,270 --> 00:17:51,110 This is going to be higher in terms of importance than this. 183 00:17:51,740 --> 00:17:56,870 Our final color for our h1 will in fact be blue. 184 00:17:58,390 --> 00:18:04,210 Remember that the cascade goes from here to here to here to here. 185 00:18:04,240 --> 00:18:12,580 Even if something that has won out on specificity, it can also lose because of the type. 186 00:18:12,610 --> 00:18:19,870 So you have to keep in mind the order of importance of the big categories, but also the order of importance 187 00:18:19,870 --> 00:18:22,060 of the small categories. 188 00:18:23,690 --> 00:18:31,820 So now it's time to try an exercise and write the code yourself so that we really solidify this knowledge 189 00:18:31,820 --> 00:18:34,370 in our minds and really get to grips with it. 190 00:18:34,700 --> 00:18:40,640 Go ahead and download the zipped starting code for the exercise from this lesson. 191 00:18:40,850 --> 00:18:48,500 Once you've extracted and opened it up inside VS Code, I want you to go inside the index.html and look 192 00:18:48,500 --> 00:18:50,930 at the starting code that we've created here. 193 00:18:51,200 --> 00:18:58,880 The goal is to not change any of the HTML, but actually write your code inside the style.css. 194 00:18:58,910 --> 00:19:04,280 And what we're trying to achieve is to turn this into this. 195 00:19:04,490 --> 00:19:07,300 And notice I've given you some little bits of hint, 196 00:19:07,310 --> 00:19:12,650 for example, the fact that every box has 10px of padding on all four sides. 197 00:19:12,680 --> 00:19:19,430 And also notice that in the CSS code there's already some existing code that basically just gets rid 198 00:19:19,460 --> 00:19:23,820 of some of the defaults and sets you up for the rest of the challenge. 199 00:19:23,820 --> 00:19:29,370 So don't change any of the existing code, either the CSS or the HTML. 200 00:19:29,970 --> 00:19:35,820 Look at the goal image, see what it's got, and you're going to need to write some code to change a 201 00:19:35,820 --> 00:19:36,830 number of things. 202 00:19:36,840 --> 00:19:41,850 So the first thing is these pieces of text should be white, 203 00:19:41,850 --> 00:19:48,060 as you can see here. It might be a little bit too difficult in terms of the contrast, but these should 204 00:19:48,060 --> 00:19:48,930 be white. 205 00:19:48,960 --> 00:19:56,400 And then notice how this text is actually inside a div that should be red. 206 00:19:56,940 --> 00:20:05,910 And similarly, down here, the final thing is that there should be a div that encloses everything and 207 00:20:05,910 --> 00:20:08,040 it should be colored purple. 208 00:20:08,070 --> 00:20:12,060 And notice that there is 10px of padding here, 209 00:20:12,090 --> 00:20:17,790 there is 10px of padding here, and there's 10px of padding here. 210 00:20:18,090 --> 00:20:23,730 There's a number of things that you have to do using CSS and using what you've learned about the CSS 211 00:20:23,730 --> 00:20:26,400 cascade in order to achieve this. 212 00:20:26,670 --> 00:20:33,570 And the reason why the cascade is really important is because you can't add any additional classes. 213 00:20:33,570 --> 00:20:36,440 You can't change any of the HTML. 214 00:20:36,450 --> 00:20:42,420 So you're going to have to use everything that you've got access to in order to achieve this outcome. 215 00:20:42,570 --> 00:20:47,580 This is a tricky challenge, and I want you to spend some time thinking about it and thinking about 216 00:20:47,580 --> 00:20:53,820 what you've learned, and referring back to maybe the previous parts of the video and revising what you've 217 00:20:53,820 --> 00:20:55,320 learned in this lesson. 218 00:20:55,530 --> 00:20:58,650 Pause the video now and complete this challenge. 219 00:21:04,690 --> 00:21:05,110 All right. 220 00:21:05,110 --> 00:21:10,180 I'm going to go through the solution so that you can check your work and make sure that you understand 221 00:21:10,180 --> 00:21:11,510 everything that's going on. 222 00:21:11,530 --> 00:21:13,540 So I'm going to pull up the goal image. 223 00:21:13,540 --> 00:21:18,550 So have it side by side with the current preview of the index.html. 224 00:21:18,580 --> 00:21:21,850 That way I can compare to see I've reached the goal or not. 225 00:21:22,060 --> 00:21:28,330 Now the first thing I need to do is change this text to white, which is the easiest because notice 226 00:21:28,330 --> 00:21:34,120 that these are in a particular class, whereas these don't have any class applied. 227 00:21:34,120 --> 00:21:38,620 So the class is "white-text", so I can go ahead and do that right here. 228 00:21:38,620 --> 00:21:44,770 Use a class selector, choose the class I want "white-text," and then go ahead and set the color of the 229 00:21:44,770 --> 00:21:46,900 text to white. 230 00:21:47,140 --> 00:21:47,980 There we go. 231 00:21:47,980 --> 00:21:49,720 So that's the first part. 232 00:21:49,720 --> 00:21:52,750 So I'm getting closer to the final outcome. 233 00:21:53,110 --> 00:21:53,560 Now, 234 00:21:53,560 --> 00:21:57,370 the next thing I need to do is to make this box red. 235 00:21:57,370 --> 00:22:01,060 So this box is the box that encloses the white text. 236 00:22:01,060 --> 00:22:08,600 So it's this particular div and notice that it's got two classes applied to it, "box" and "inner-box." 237 00:22:08,600 --> 00:22:13,700 So this "inner-box" isn't actually present as a class on any of the rest of the divs, 238 00:22:13,700 --> 00:22:16,430 so I can select that quite easily. 239 00:22:16,640 --> 00:22:25,160 Up here next to my other box, I'm going to select the "inner-box" class and I'm going to set the background 240 00:22:25,160 --> 00:22:27,050 color to red. 241 00:22:27,170 --> 00:22:32,140 Now if we look inside our preview, you can see we're getting pretty close. 242 00:22:32,150 --> 00:22:38,090 Now, the next difference is this final outside box, which I want to be purple. 243 00:22:38,300 --> 00:22:46,250 This is the div that encloses everything, which is this one that has an ID of "outer-box." 244 00:22:46,250 --> 00:22:51,470 This is really the only thing that differentiates this div from any of the other divs 'cause they all 245 00:22:51,470 --> 00:22:54,110 share the class of "box." 246 00:22:54,110 --> 00:22:56,390 This red div has a class of "box." 247 00:22:56,390 --> 00:23:04,130 This blue div has the class of "box" and this outer div also has that same class, which is why we're 248 00:23:04,130 --> 00:23:11,330 able to apply the 10px of padding to all three simply using the original code of box. 249 00:23:11,990 --> 00:23:18,500 If I want to target this outer box, then I have to use the thing that's unique to it, which is the 250 00:23:18,500 --> 00:23:18,920 ID. 251 00:23:19,400 --> 00:23:30,500 So now I'm going to select the ID called outerbox and I'm going to set its background color to purple. 252 00:23:30,740 --> 00:23:35,690 And now you can see I have achieved the final goal outcome. 253 00:23:36,110 --> 00:23:43,070 The important thing here to realize is firstly, we don't need to add any padding to the inner box or 254 00:23:43,070 --> 00:23:50,420 the outer box because all three of those divs share a class called box and that 10px of padding 255 00:23:50,420 --> 00:23:52,070 is already applied there. 256 00:23:52,190 --> 00:23:58,550 Notice if I go ahead and go in here and set the padding, it doesn't change anything because it's already 257 00:23:58,550 --> 00:24:00,080 got 10px of padding, 258 00:24:00,080 --> 00:24:07,550 but because the ID selector is more specific, if I say change the padding to 50 pixels, then it would 259 00:24:07,550 --> 00:24:10,220 actually be the one that will come out trumps. 260 00:24:11,060 --> 00:24:19,880 The second thing that I wanted you to realize is that the ID selector is more specific than the class 261 00:24:19,880 --> 00:24:20,390 selector. 262 00:24:20,390 --> 00:24:26,750 So even though for all three divs, I've set the background color to blue because this selects an ID, 263 00:24:26,780 --> 00:24:28,640 this will override it. 264 00:24:28,760 --> 00:24:34,550 Now the other thing you have to realize is in order to set the "inner-box" background color to red, this 265 00:24:34,550 --> 00:24:40,220 rule actually has to be below this rule because watch as I move it up. 266 00:24:40,340 --> 00:24:46,730 Now, in this case, we don't have a red box anymore because these two have the same specificity. 267 00:24:46,730 --> 00:24:49,310 They're both selecting a class here. 268 00:24:49,310 --> 00:24:50,390 We're setting it to red. 269 00:24:50,420 --> 00:24:56,050 But later on we set all the divs with a "box" class to blue. 270 00:24:56,060 --> 00:25:00,410 So this refers to the position of our CSS rule. 271 00:25:01,430 --> 00:25:08,000 Hopefully, this will have given you some practical experience with the CSS cascade and reinforce some of the 272 00:25:08,000 --> 00:25:10,040 lessons that we learned earlier. 273 00:25:10,460 --> 00:25:17,000 In the next lesson, we're going to learn how to combine different selectors so that we narrow down 274 00:25:17,000 --> 00:25:23,420 on a particular element that we want to select on-screen rather than simply broad stroke, setting the 275 00:25:23,420 --> 00:25:27,020 CSS of everything. For all of that and more, 276 00:25:27,050 --> 00:25:28,550 I'll see you on the next lesson. 29158

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