Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,140 --> 00:00:06,020
In the last lesson, we looked at how the CSS cascade works when there are multiple rules that conflict
2
00:00:06,020 --> 00:00:06,920
with each other.
3
00:00:06,920 --> 00:00:13,400
But in this lesson, we're going to focus more on how to combine different CSS selectors so that we
4
00:00:13,400 --> 00:00:22,010
can target a very specific element in our website in order to apply our style. From the previous coding
5
00:00:22,010 --> 00:00:28,910
exercise, you might have remembered that there is a part where we had a paragraph element that we wanted
6
00:00:28,910 --> 00:00:33,860
to be yellow and another paragraph element that we wanted to be white.
7
00:00:34,040 --> 00:00:43,100
When we apply the CSS style to target all of the P tags and we give it a particular color, then what's
8
00:00:43,100 --> 00:00:49,400
going to happen is everything that is a paragraph tag is going to be turned yellow.
9
00:00:49,580 --> 00:00:58,850
In our case, we changed this white text by giving this paragraph tag a specific class which we set to
10
00:00:58,850 --> 00:01:00,390
"white-text".
11
00:01:00,390 --> 00:01:07,170
Now, you can imagine if you had lots of different things in your website and they all had different
12
00:01:07,170 --> 00:01:08,730
color requirements,
13
00:01:08,730 --> 00:01:12,270
you can't go around setting each one with a different class, right?
14
00:01:12,270 --> 00:01:16,410
That would be a lot of work and a lot of clutter in your HTML.
15
00:01:16,500 --> 00:01:18,540
So what can we do instead?
16
00:01:18,540 --> 00:01:24,300
Well, we can combine different selectors in order to select something specific.
17
00:01:24,510 --> 00:01:32,190
So in this case, notice that the paragraph that we want to set to color white happens to live inside
18
00:01:32,190 --> 00:01:37,560
a different div and this div already has a different class.
19
00:01:37,590 --> 00:01:40,800
It has "box", but it also has "inner-box".
20
00:01:40,800 --> 00:01:48,630
And in our case, we only wanted the text in the "inner-box" right here, to be turned into white.
21
00:01:48,630 --> 00:01:57,420
So we can use that piece of information and combine these two things in order to select a specific element.
22
00:01:57,720 --> 00:02:06,750
What this rule does is it first looks at the elements with this particular class, and then it looks
23
00:02:06,750 --> 00:02:10,320
at any of the descendants of that class,
24
00:02:10,320 --> 00:02:17,070
so anywhere inside that div could be one level down, it could be three levels deep,
25
00:02:17,070 --> 00:02:24,210
as long as it's enclosed inside the div, it counts as a descendant and we're looking for a paragraph
26
00:02:24,210 --> 00:02:24,970
element.
27
00:02:24,990 --> 00:02:31,200
And once we found that, then that is the one that's going to get a white color.
28
00:02:31,680 --> 00:02:38,550
And now when we run this code, you'll notice that even though we haven't added any new classes to this
29
00:02:38,550 --> 00:02:46,710
paragraph element, it has been specifically selected using this combined selector right here, turning
30
00:02:46,710 --> 00:02:48,240
the text white.
31
00:02:48,780 --> 00:02:56,160
There are different ways that we can combine CSS selectors and I want to show you some of these different
32
00:02:56,160 --> 00:02:57,030
rules.
33
00:02:57,360 --> 00:03:03,480
The first one is the group rule, and this is done using a comma.
34
00:03:03,510 --> 00:03:09,030
You can have one selector here and then another selector
35
00:03:09,180 --> 00:03:15,510
and to separate them, we've got this comma and a space
36
00:03:15,510 --> 00:03:24,540
and what the grouping does is it selects both of the selectors or even more, 2 or 3 different selectors
37
00:03:24,540 --> 00:03:29,340
and applies the same style to the entire group.
38
00:03:29,340 --> 00:03:37,620
So everything that's selected now, we're going to try and apply what we just learned grouping selectors
39
00:03:37,620 --> 00:03:43,110
in order to have the preview of our index.html look like this.
40
00:03:43,140 --> 00:03:49,020
We want both the h1 and h2 to have a color of blueviolet.
41
00:03:49,050 --> 00:03:56,670
Let's put this into practice by going to the current lesson, downloading the starting files as a zipped
42
00:03:56,670 --> 00:04:01,340
file, extracting it and opening it in VS Code.
43
00:04:01,340 --> 00:04:08,450
Once you've extracted the files, I want you to first go into the index.html file and I want you to
44
00:04:08,450 --> 00:04:11,630
take a look at the structure of the starting file.
45
00:04:11,870 --> 00:04:17,510
It's really important for any of the upcoming challenges that you don't change any of the HTML code.
46
00:04:17,510 --> 00:04:21,140
So don't add any extra classes, don't add any IDs,
47
00:04:21,140 --> 00:04:25,490
basically don't touch this entire index.html file.
48
00:04:25,490 --> 00:04:31,220
Instead, you're going to be writing all of your code inside the style.css and you're going to be using
49
00:04:31,220 --> 00:04:38,180
CSS and more specifically, the different combinations of CSS selectors in order to carry out the challenge
50
00:04:38,180 --> 00:04:38,930
goals.
51
00:04:39,380 --> 00:04:46,940
As you might remember, the first goal that we're trying to achieve is to target both the h1 and the
52
00:04:46,940 --> 00:04:54,740
h2 and make sure that they both have a blueviolet text color and we're going to group our selectors
53
00:04:54,740 --> 00:04:56,000
to achieve this.
54
00:04:56,180 --> 00:04:59,600
Pause the video and write your code inside the style.css
55
00:05:00,700 --> 00:05:02,260
to complete the challenge.
56
00:05:06,780 --> 00:05:07,140
All right.
57
00:05:07,140 --> 00:05:09,090
So remember to group a selector.
58
00:05:09,090 --> 00:05:13,740
We first write a selector, and then we add a comma,
59
00:05:13,740 --> 00:05:16,680
and then we add the second group of selectors.
60
00:05:16,710 --> 00:05:21,810
Now, in this case, I'm using the element selector, but it could be that you're grouping different
61
00:05:21,810 --> 00:05:25,170
classes, you could be grouping different IDs,
62
00:05:25,170 --> 00:05:31,350
it doesn't really matter as long as you're aware that you have two different selectors separated by
63
00:05:31,350 --> 00:05:32,250
a comma.
64
00:05:32,520 --> 00:05:36,480
Here, we're going to change the color to a blueviolet color.
65
00:05:36,480 --> 00:05:44,310
And once I've done that, you can see we've got these two bits, both with the same CSS applied to it.
66
00:05:44,310 --> 00:05:49,440
And this can be really handy when you're trying to save some time targeting different areas of your
67
00:05:49,440 --> 00:05:50,250
website.
68
00:05:51,240 --> 00:05:54,090
All right, let's look at some other different combiners.
69
00:05:54,510 --> 00:06:03,660
Now we can use the right angle bracket (>) in order to select a child of another selector.
70
00:06:03,780 --> 00:06:11,350
So in this case, the first selector is the parent and the second selector is the child.
71
00:06:11,350 --> 00:06:21,130
What this means is that if we had a div where it opens here and it closes here, then inside here a
72
00:06:21,130 --> 00:06:22,720
direct descendant,
73
00:06:22,720 --> 00:06:26,560
so just one level down, we might have a child.
74
00:06:26,560 --> 00:06:28,660
Let's say it's another div.
75
00:06:29,140 --> 00:06:35,110
Well this then is the parent, and this is the child.
76
00:06:35,200 --> 00:06:42,880
And the important thing is that this relationship is only one generation deep. In this case, when we
77
00:06:42,880 --> 00:06:51,610
want to select this particular div, then we can use this method by putting the parent the right angle
78
00:06:51,610 --> 00:06:58,450
bracket and then the child selector in order to select this particular element.
79
00:06:58,480 --> 00:07:03,820
And the most important thing to remember here is that it's a direct child.
80
00:07:03,820 --> 00:07:06,430
It's not a grandchild, not a great grandchild,
81
00:07:06,430 --> 00:07:16,180
it has to be only one level nested inside. This selector has to be only one level inside this one.
82
00:07:16,750 --> 00:07:18,520
All right, let's try a practice run.
83
00:07:18,670 --> 00:07:28,450
Use this selector in order to change the index.html, to set the first paragraph tag to a firebrick
84
00:07:28,450 --> 00:07:29,170
color.
85
00:07:29,290 --> 00:07:33,430
This is what you want your preview to look like.
86
00:07:33,550 --> 00:07:41,560
The next goal is to change the color of this paragraph element to a firebrick color.
87
00:07:42,730 --> 00:07:48,910
And in order to do this we have to again study how we can select it specifically.
88
00:07:48,940 --> 00:07:53,650
Now, notice here that it's got a class of "done", but so do other things.
89
00:07:53,650 --> 00:07:59,080
It's got a paragraph element, but there are also other paragraph elements on screen.
90
00:07:59,380 --> 00:08:06,340
I want you to use what you've learned about the child selector in order to select this particular element
91
00:08:06,340 --> 00:08:08,050
and change its color.
92
00:08:08,080 --> 00:08:10,540
Pause the video now and give this a go.
93
00:08:12,680 --> 00:08:13,040
All right.
94
00:08:13,040 --> 00:08:21,140
So we mentioned that a child selector allows us to choose a parent and then specify something that is
95
00:08:21,140 --> 00:08:22,760
one level deep.
96
00:08:22,760 --> 00:08:28,250
So in this case, if this div was the parent, then you can see it has two child-elements.
97
00:08:28,250 --> 00:08:31,760
One is this paragraph and another is the ul.
98
00:08:31,790 --> 00:08:37,340
Whereas these li's, for example, they would not be children elements, they're actually grandchildren.
99
00:08:37,429 --> 00:08:41,299
Let's use what we learnt in order to target this particular paragraph
100
00:08:41,299 --> 00:08:42,650
tag. In English,
101
00:08:42,650 --> 00:08:50,060
what our rule is going to specify is, "Select the thing that has a class of "box", and look at its children
102
00:08:50,060 --> 00:08:52,880
and find a paragraph element."
103
00:08:53,270 --> 00:08:59,870
This way we distinguish this paragraph element from this one because it's not inside a div called "box".
104
00:08:59,870 --> 00:09:01,910
It doesn't have a parent with that class,
105
00:09:01,910 --> 00:09:07,910
and also similar with this paragraph, it also doesn't have a parent that has a class of "box".
106
00:09:07,910 --> 00:09:09,400
So let's go in here.
107
00:09:09,410 --> 00:09:17,970
Let's first select our parent using the selector for a class and then using the right angle bracket,
108
00:09:18,000 --> 00:09:21,450
we're going to say, let's look for a direct descendant
109
00:09:21,450 --> 00:09:27,180
that is a paragraph element and then let's set the color to a firebrick.
110
00:09:27,960 --> 00:09:35,760
You can see here we've managed to set this particular paragraph's color to firebrick, but left these
111
00:09:35,760 --> 00:09:37,530
other paragraphs alone.
112
00:09:37,890 --> 00:09:42,750
The next combination we want to look at is the descendant combination.
113
00:09:43,080 --> 00:09:45,450
Here we've got two selectors,
114
00:09:45,480 --> 00:09:51,630
this is the ancestor and this is the descendant.
115
00:09:51,960 --> 00:09:58,140
So notice that here all we've got is a single space between the two selectors.
116
00:09:58,290 --> 00:10:05,820
And what this means is that our descendant selector is going to apply the style to this descendant as
117
00:10:05,820 --> 00:10:10,110
long as it has an ancestor that matches this selector.
118
00:10:10,110 --> 00:10:14,430
So that means that you can have many, many levels deep.
119
00:10:14,460 --> 00:10:20,700
For example, you could have a class here, you could have a different class here, and then maybe you
120
00:10:20,700 --> 00:10:22,830
have a paragraph element in here.
121
00:10:22,830 --> 00:10:29,490
So then you can specify the left hand selector to select on this particular class.
122
00:10:29,490 --> 00:10:38,520
And as long as somewhere within its enclosing brackets there is a paragraph element, then this will
123
00:10:38,520 --> 00:10:43,170
be a valid descendant to select and apply your styles to.
124
00:10:43,200 --> 00:10:45,240
Let's try this out in code.
125
00:10:45,240 --> 00:10:53,790
What we want to do is we're going to try and select these three bullets here and give them a blue color,
126
00:10:53,880 --> 00:10:59,700
and we're going to use the descendant combination. In order to select these three here,
127
00:10:59,700 --> 00:11:06,690
if we look at the index.html, you can see that we've clearly got three list-item elements,
128
00:11:06,900 --> 00:11:10,110
I don't want you to select on the list-item.
129
00:11:10,110 --> 00:11:15,590
We're going to practice using the descendant selector instead, make sure that you use the descendant
130
00:11:15,590 --> 00:11:19,310
combination in order to select these three items.
131
00:11:19,310 --> 00:11:26,360
And I want you to imagine that maybe there are other list item elements in the rest of the website and
132
00:11:26,360 --> 00:11:30,110
we don't want to style them the same as what we've got here.
133
00:11:30,110 --> 00:11:36,080
So we're trying to turn the text blue just for these three bullet points and we're not selecting on
134
00:11:36,080 --> 00:11:37,700
the list-item element.
135
00:11:37,730 --> 00:11:40,730
We're instead using the descendant selectors.
136
00:11:40,760 --> 00:11:42,680
Pause the video and give that a go.
137
00:11:45,410 --> 00:11:45,770
All right.
138
00:11:45,770 --> 00:11:51,020
So as I mentioned previously, the easiest thing here would of course, be simply to select all the
139
00:11:51,020 --> 00:11:51,860
li's.
140
00:11:51,860 --> 00:11:54,560
But this is a very short website.
141
00:11:54,590 --> 00:11:58,160
Now imagine that your whole website is 2000 lines long,
142
00:11:58,190 --> 00:12:03,700
there probably will be a lot of other li elements that you don't want to select on and apply this style.
143
00:12:03,710 --> 00:12:06,470
That's why we're going to use a descendant selector.
144
00:12:06,500 --> 00:12:09,050
Also, it's good practice for our learning.
145
00:12:09,260 --> 00:12:17,280
So in this case, notice that the li's are a grandchild of this div, so we can simply select the
146
00:12:17,280 --> 00:12:25,230
box class and then use a space to say, let's find all the descendants that are li and change their
147
00:12:25,230 --> 00:12:26,880
color to blue.
148
00:12:26,880 --> 00:12:29,520
And that changes these three bullets.
149
00:12:29,520 --> 00:12:36,150
And notice because of this rule, it means that if I have any other li's down here, then they don't
150
00:12:36,150 --> 00:12:40,620
get affected at all because my rule is very specific.
151
00:12:41,100 --> 00:12:47,940
And also notice how in this case, if I use the child selector, it's actually not going to work because
152
00:12:47,940 --> 00:12:53,490
the li is two levels deep relative to this div that we're selecting.
153
00:12:53,490 --> 00:12:59,250
So we could select on the parent which has the class, "list", but if we wanted to use the descendant selector
154
00:12:59,250 --> 00:13:06,000
then we would have to use "box" as a class and then select all the li's that are a descendant using
155
00:13:06,000 --> 00:13:07,320
this syntax.
156
00:13:08,560 --> 00:13:12,580
The next method I want to talk about is chaining selectors.
157
00:13:12,700 --> 00:13:16,900
And this looks really similar to the previous one where we had descendant selectors.
158
00:13:16,900 --> 00:13:19,480
So it's really important to pay attention here.
159
00:13:19,870 --> 00:13:26,350
When you chain a selector, effectively what you're doing is you're saying apply these styles to the
160
00:13:26,350 --> 00:13:30,610
instances where all the selectors are true.
161
00:13:30,760 --> 00:13:37,750
If we look at the way that we chain selectors, you can see we've got a selector and then we immediately
162
00:13:37,750 --> 00:13:39,700
add another selector.
163
00:13:39,730 --> 00:13:44,420
There is no space in between the two selectors whatsoever.
164
00:13:44,440 --> 00:13:53,920
So what this might look like is let's say you had an h1 and this h1 also has some other attributes,
165
00:13:53,950 --> 00:13:57,060
maybe it's got an ID of "title",
166
00:13:57,070 --> 00:14:03,430
maybe it's also got a class that's equal to "big" and "heading".
167
00:14:03,520 --> 00:14:09,140
It's got two classes applied, one ID, and it's also an h1 element.
168
00:14:09,260 --> 00:14:16,160
If we had a whole bunch of other elements in our code which also had the same ID or the same class,
169
00:14:16,160 --> 00:14:21,260
then we can use this chaining method to be really, really specific.
170
00:14:21,380 --> 00:14:29,450
That is the purpose of chaining. In order to get hold of this particular h1, we could say we're looking
171
00:14:29,450 --> 00:14:38,720
for an h1 and then without any spaces we add immediately, say a pound sign to select on the ID of
172
00:14:38,720 --> 00:14:39,650
"title",
173
00:14:39,860 --> 00:14:47,780
now the selector says look for an h1 that also has an ID of "title" and then we can even add on another
174
00:14:47,780 --> 00:14:48,020
one.
175
00:14:48,020 --> 00:14:54,800
So we could say it also has the class of "big" and it also has the class of "heading".
176
00:14:55,910 --> 00:15:05,270
Now we have a super, super specific selector where we've chained all of these selectors together to
177
00:15:05,270 --> 00:15:08,660
apply to just one single element.
178
00:15:09,110 --> 00:15:11,970
Now, there could be many h1's,
179
00:15:11,990 --> 00:15:13,760
there shouldn't be, but there could.
180
00:15:13,790 --> 00:15:19,700
There could be many elements with the same ID again, there shouldn't be, but it could happen.
181
00:15:19,700 --> 00:15:27,530
But more commonly, there probably will be many elements with the same class, but maybe there won't
182
00:15:27,530 --> 00:15:30,950
be an element with both of these classes.
183
00:15:31,070 --> 00:15:41,240
So remember you chain selectors by having no space between the selectors and your selector includes
184
00:15:41,240 --> 00:15:42,770
that symbol at the beginning.
185
00:15:42,770 --> 00:15:53,390
So it could be dot (.) for classes, it could be the pound sign (#) for IDs and it could have nothing in front
186
00:15:53,390 --> 00:15:55,730
where it's just the element.
187
00:15:56,570 --> 00:16:03,530
In the case of the element, if you're trying to chain this selector with anything else, this has to
188
00:16:03,530 --> 00:16:07,880
go first, because otherwise it can be really confusing.
189
00:16:07,880 --> 00:16:14,570
Let's say you had a class of "big" and you wanted to say, well it also is an h1, because there's no
190
00:16:14,570 --> 00:16:16,220
space when we chain,
191
00:16:16,250 --> 00:16:21,130
this might just look like a class called "bigh1", which is not what you want.
192
00:16:21,140 --> 00:16:25,070
Always, always start off with the element,
193
00:16:25,070 --> 00:16:32,630
if you want to chain an element and then you can add on the class using any sort of dot or you could
194
00:16:32,630 --> 00:16:39,680
use the pound sign to add any sort of ID and remember leave no spaces in between
195
00:16:39,680 --> 00:16:45,980
if you want to say that all of these selectors are in a single element.
196
00:16:46,760 --> 00:16:52,040
And this is to differentiate when you say want to use the descendant selector, where you say that I'm
197
00:16:52,040 --> 00:16:59,690
looking for something that has this particular class, but it also has a parent which is an h1, this
198
00:16:59,690 --> 00:17:03,320
is when you're looking for the descendant combination.
199
00:17:04,280 --> 00:17:12,650
So now your challenge is to figure out how to only select these two bullet points in order to turn them
200
00:17:12,650 --> 00:17:15,890
into the seagreen color that you see right here.
201
00:17:16,400 --> 00:17:19,599
These are the two items that we want to select.
202
00:17:19,609 --> 00:17:23,180
So we could go for the class, which is "done",
203
00:17:23,180 --> 00:17:28,760
but notice that there's other items with the class "done" and we can't change the HTML code.
204
00:17:29,000 --> 00:17:35,750
How can we use this chaining method in order to get hold of these two items?
205
00:17:35,840 --> 00:17:38,510
Well, notice what's very specific about this.
206
00:17:38,540 --> 00:17:43,640
These are list-item elements that have this particular class.
207
00:17:43,850 --> 00:17:50,310
We can't select on all the list items and we can't select on all the ones with a class of "done",
208
00:17:50,310 --> 00:17:55,200
but we can chain these two selectors together using what we just learned.
209
00:17:55,320 --> 00:18:01,440
Pause the video and try to make these two bullets a color of seagreen.
210
00:18:03,710 --> 00:18:04,160
All right.
211
00:18:04,160 --> 00:18:06,950
So we're going to chain these two selectors.
212
00:18:06,950 --> 00:18:14,030
We're going to look for all the list-item elements that have the class "done" to differentiate between
213
00:18:14,030 --> 00:18:20,060
paragraph elements that have a class of "done" and this list-item element that doesn't have the class
214
00:18:20,060 --> 00:18:22,730
"done" and make it really, really specific,
215
00:18:22,730 --> 00:18:26,030
so we select just these two list-item elements.
216
00:18:26,150 --> 00:18:30,290
So first we select the element, which is list-item element.
217
00:18:30,350 --> 00:18:36,830
And remember, there's no space between the two selectors when we want to chain, and the second selector
218
00:18:36,830 --> 00:18:45,110
is the class selector of "done." We're going to change the color to seagreen, like this.
219
00:18:46,160 --> 00:18:51,800
Now remember that when we're chaining selectors, you can imagine that if we have first had the class
220
00:18:51,800 --> 00:18:58,510
selector and then we add the list-item element, it thinks that we're looking for a class called ".doneli",
221
00:18:58,760 --> 00:19:06,720
which doesn't make any sense at all. Because our IDs and our class selectors have a special symbol,
222
00:19:06,720 --> 00:19:12,930
we always start off by selecting on the element and then we add the other selectors.
223
00:19:13,260 --> 00:19:19,380
You can add it in order, it could be ".done", and then you can add an ID, or you can select on the ID
224
00:19:19,410 --> 00:19:20,670
first and then the class.
225
00:19:20,670 --> 00:19:25,740
It doesn't really matter as long as the first item in the chain is your element.
226
00:19:26,620 --> 00:19:32,170
Now, the final thing I want to mention is we've looked at different ways of combining selectors, but
227
00:19:32,170 --> 00:19:35,950
remember that we can also combine these different combinations together.
228
00:19:35,950 --> 00:19:41,230
It gets a little bit more complex this way, but just in case you see it out in the world, I wanted
229
00:19:41,230 --> 00:19:42,790
to quickly explain this.
230
00:19:42,910 --> 00:19:49,720
So imagine if you wanted to select on something that has an ancestor that matches this selector, but
231
00:19:49,720 --> 00:19:57,280
then you use the chaining method in order to specifically select this item with these two selectors,
232
00:19:57,280 --> 00:20:02,980
then you can combine all of this together and add that space in there and remove that space in there
233
00:20:02,980 --> 00:20:07,000
or use the group and you can combine lots of different combinations.
234
00:20:07,510 --> 00:20:16,210
Let's try this out and target this particular item right here and give it a font size of 0.5rem.
235
00:20:16,210 --> 00:20:19,480
So it's much smaller than everything else on screen.
236
00:20:19,870 --> 00:20:25,450
And if you look at the code, it's a little bit tricky because this is a paragraph element that has
237
00:20:25,450 --> 00:20:30,200
a class of "done", but there's also the same one up here.
238
00:20:30,200 --> 00:20:31,700
But we don't want to select this one,
239
00:20:31,700 --> 00:20:37,850
we just want this one and we want to set its font size to 0.5rem.
240
00:20:38,300 --> 00:20:43,220
So use what you learned and try out the different combinations in order to achieve that
241
00:20:43,220 --> 00:20:45,410
to make this a tiny font size.
242
00:20:45,620 --> 00:20:46,640
Pause the video,
243
00:20:46,640 --> 00:20:47,540
give that a go.
244
00:20:50,540 --> 00:20:50,960
All right.
245
00:20:50,960 --> 00:20:54,950
What is different about this element and this element?
246
00:20:55,100 --> 00:21:02,300
Well, it's the fact that this one is inside a ul, whereas this one is inside a div.
247
00:21:03,350 --> 00:21:06,800
Normally inside a ul, you would see list-item elements,
248
00:21:06,800 --> 00:21:13,190
but in this case, just for the example's sake, we've put in a paragraph element which is totally valid
249
00:21:13,190 --> 00:21:19,070
as well, because you might have list elements that come up afterwards and it could just be a line inside
250
00:21:19,070 --> 00:21:20,360
the unordered list.
251
00:21:20,720 --> 00:21:28,760
So now in order to select it, we're going to find a parent of ul that has a paragraph element that
252
00:21:28,760 --> 00:21:30,260
has a class of "done".
253
00:21:30,920 --> 00:21:32,120
Let's do that here.
254
00:21:32,120 --> 00:21:41,660
So a ul as the ancestor and then a paragraph element and then a class of "done" and we set the font-size
255
00:21:41,660 --> 00:21:46,400
to 0.5rem and you can see that's achieved this.
256
00:21:46,430 --> 00:21:51,870
Now the other way of doing this is of course using the child selector, which does the same thing right
257
00:21:51,870 --> 00:21:57,600
here, because it is an ancestor and it's also a parent in this case.
258
00:21:57,720 --> 00:22:04,170
So normally, unless you're sure that you only want the parent child relationship, I prefer to use
259
00:22:04,170 --> 00:22:08,280
the descendant selector because it's just a little bit more broad stroke,
260
00:22:08,280 --> 00:22:13,350
and normally you'll want to apply your style to multiple things that apply to that same rule.
261
00:22:13,380 --> 00:22:18,960
But both of these options are totally valid solutions, and I would consider you completely correct
262
00:22:18,960 --> 00:22:20,520
if you did either of them.
263
00:22:20,730 --> 00:22:26,250
The important thing for you to understand here is we've got an ancestor selector,
264
00:22:26,280 --> 00:22:30,200
we're using the space in order to say that this is the ancestor,
265
00:22:30,210 --> 00:22:33,090
this is not what we actually want to change the style to,
266
00:22:33,090 --> 00:22:40,110
but we're also using the chaining method to say, "This is quite specific, and this is what we want to target."
267
00:22:40,590 --> 00:22:46,770
And notice that when you hover over these selectors, you actually see which element it's selecting as
268
00:22:46,770 --> 00:22:49,470
well, which can be really handy sometimes.
269
00:22:50,800 --> 00:22:57,130
Hopefully this has given you a little bit of insight into how different CSS selectors can be combined
270
00:22:57,130 --> 00:23:00,430
together in order to target specific things on screen.
271
00:23:00,640 --> 00:23:06,970
In the next lesson, we're going to look at the CSS position property so that we can learn more about
272
00:23:06,970 --> 00:23:10,140
how the positioning of items works in CSS.
273
00:23:10,150 --> 00:23:12,790
So for all of that and more, I'll see you there.
29167
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.