Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
0 All right. So in the last lesson we looked at what this syntax means and we learned all about how to combine 1
selectors in CSS code. 2
Now if you haven't taken a look at that then I strongly recommend you do because it's really really 3
useful so that you can understand what exactly is going on over here. 4
But now we're going to continue to refactor our code. 5
So the next thing I want to do relates to the fact that we've got certain sections on our web site that 6
have a colored background where the text is white and then we have other sections where the background 7
is white and the text is black. 8
So this is a repeated pattern across our web site. 9
So I want to capture that and refactor our code to make it a little bit more modular and reusable. 10
So what I'm going to do is I'm going to look through my code and give each of these sections a class 11
based on whether it's a colored section or if it is a white section. 12
So the first title section is a colored section, 13
the second section, features section, is a white section, and then testimonials was colored, I think, 14
and then press was also a colored section, and then pricing was a white section, 15
and finally the cta was a colored section, and the footer was a white section. 16
All right. 17
So now all of our sections have a class depending on whether they should be white or if they should 18
be colored. 19
And if I hit save I can now go and create some of these sections up top so just below containers. 20
I'm going to add another comment that's called sections, and I'm going to add our classes here, 21
the colored-section and the white-section. 22
All right. 23
So now if we take a look at our code you can see that for the colored sections we tend to add a background 24
color of that bright red pinkish color and then we give the text a white color. 25
Now for the white sections we tend to just give it a background color of white and maybe a little later on 26
we decide that we want to add other changes to our different sections, 27
but at the moment that's basically all that each section has. 28
So let's put that in here. 29
So I'm going to remove these two bits of code and I'm going to put it inside the colored section and 30
then the white section is simply going to have a background color of white. 31
And now I can go through my code and remove some of the repeated declarations. So, in the case of the 32
testimonial section, even though it's a colored section because it has white tags and has a background 33
color and we've already given it a class of colored-section, 34
it is slightly different from the other colored sections because it has this kind of peachy color rather 35
than this bright pinkish red. 36
So what we can do here is we can delete the part that's repeated, which is the 37
white text, because it's already inside a section that has a class of colored-section, which has that 38
text color that's applied, but we can override the background color by applying a style to our id. 39
And it's important to remember that there is a hierarchy between different types of selectors, 40
as we mentioned before. So ids are the most specific and their styles get applied preferentially over 41
everything else, 42
then next comes classes, and finally comes these HTML elements. 43
So if I right click and inspect to go into the Chrome Developer Tools and I select our section here 44
which has an HTML element of section, 45
class of colored-section, and an id of testimonials, 46
you can see that even though colored-section is applying the background color of that bright pinkish 47
color and id testimonials is applying this more peachy color, 48
you can see that this one gets overridden and it's shown as being crossed out in the Chrome Developer 49
Tools. 50
So if we didn't have this style that's applied in the id, which as we said is more specific, has higher 51
ranking, then it would default to the colored-section background color, but because we do, then this one 52
is going to override the other color. And it's pretty much the same thing 53
inside the press section as well. 54
All right. So the last one that we have is the cta section which we can now basically delete because 55
the section already has a class of colored-section so we don't need to write out that code again. 56
So let's hit save and refresh our web site and hopefully absolutely nothing has changed. 57
So we're doing a good job with our refactoring. 58
Now another thing that you might have noticed up here is that, because we're targeting the container that's 59
inside the title section, we don't actually need this extra title id. 60
We can actually just combine these two into the same selector and we can delete that specific title 61
id selector.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.