1
00:00:05,120 --> 00:00:08,900
Welcome back, everyone, to this lecture, we're going to discuss selectors.

2
00:00:10,210 --> 00:00:15,970
We've seen already that we can use divs and Spann's to create containers that apply styling to only

3
00:00:15,970 --> 00:00:18,460
certain elements within those dips and spans.

4
00:00:18,700 --> 00:00:24,250
Even if they share the same tech like a paragraph outside of a div versus a paragraph inside a div,

5
00:00:24,730 --> 00:00:30,610
however, we can use selectors like Class An ID to have a lot more control and flexibility over this.

6
00:00:31,870 --> 00:00:36,730
Let's imagine a situation where class and it would be very useful to us more than what we can do with

7
00:00:36,730 --> 00:00:37,510
just a div.

8
00:00:37,840 --> 00:00:39,700
Imagine the following HTML code.

9
00:00:40,090 --> 00:00:41,740
I have three paragraphs here.

10
00:00:42,220 --> 00:00:45,400
Two are outside the div and one is inside the div.

11
00:00:45,550 --> 00:00:47,950
I can see the text says outside div.

12
00:00:47,980 --> 00:00:52,120
The next text says inside div and then the third text says also outside div.

13
00:00:52,630 --> 00:00:59,710
Now imagine I wanted to apply some sort of unique styling to each individual paragraph, so I want these

14
00:00:59,710 --> 00:01:05,200
three paragraphs to each have their own unique text color, for instance, right now with the use of

15
00:01:05,200 --> 00:01:06,550
divs and span's.

16
00:01:06,760 --> 00:01:08,320
We don't really have a good way to do this.

17
00:01:08,860 --> 00:01:14,950
I right now have separated out the paragraphs from being inside the device, but then I also have a

18
00:01:14,950 --> 00:01:19,720
paragraph tag within the div, and I'm not really sure yet which one's going to be more specific.

19
00:01:19,930 --> 00:01:25,990
So I'm running into a bit of a conundrum here where I can't figure out a way, even with divs, to uniquely

20
00:01:25,990 --> 00:01:28,780
style each of the three paragraphs.

21
00:01:29,050 --> 00:01:31,630
This is where classes and ideas can come to help us.

22
00:01:32,830 --> 00:01:37,990
So we can assign elements a class attribute with a specific name for CIUSSS purposes.

23
00:01:38,410 --> 00:01:43,990
Classes are typically use friendships to group the styling everything inside the div container together

24
00:01:44,380 --> 00:01:48,040
and classes can be repeatedly used across a web page across elements.

25
00:01:49,020 --> 00:01:55,140
Then there's also an ID attribute, which can be used to also connect for CSA styling, but the IDs

26
00:01:55,140 --> 00:01:59,580
should be completely unique and used for only a single element on the web page.

27
00:01:59,850 --> 00:02:03,870
So classes you can use more than once and for many different types of elements.

28
00:02:04,080 --> 00:02:07,710
IDs should be unique for that particular element that you want to style.

29
00:02:08,009 --> 00:02:15,450
Let's revisit our HTML example, where I want to apply some sort of CSS styling to each individual paragraph

30
00:02:15,450 --> 00:02:17,730
that is different and unrelated to each other.

31
00:02:18,300 --> 00:02:23,760
What I could do is for the paragraphs that are outside the div is assign them a unique ID.

32
00:02:24,900 --> 00:02:32,550
So what I do is inside the HTML, I create an ID attribute and assign it to a unique value.

33
00:02:32,910 --> 00:02:37,690
Notice how the first paragraph tag has an ID equal to the value one.

34
00:02:37,710 --> 00:02:38,770
That's just a string code.

35
00:02:38,790 --> 00:02:44,880
You can choose and then at the very bottom outside the div, I have the paragraph with the ID attribute

36
00:02:44,880 --> 00:02:45,720
equal to two.

37
00:02:46,080 --> 00:02:51,420
I cannot use this as unique identifiers for those specific paragraphs, so I don't need to worry about

38
00:02:51,420 --> 00:02:54,900
having to assign some text color to all paragraph elements.

39
00:02:55,110 --> 00:02:59,880
I can now assign it to the specific IDs, then for something like a div.

40
00:03:00,150 --> 00:03:06,420
If I wanted to style everything inside that div, I could assign that a class and the class is something

41
00:03:06,420 --> 00:03:08,520
I can use over and over again on the web page.

42
00:03:08,760 --> 00:03:13,950
So if I create another div on this web page, it's OK for me to assign it to the same class.

43
00:03:14,400 --> 00:03:21,600
And note now I have three essentially unique ways of grabbing these elements and assigning them styles.

44
00:03:21,840 --> 00:03:27,600
So now CIUSSS is going to be able to actually style these paragraphs different things like different

45
00:03:27,600 --> 00:03:28,260
text colors.

46
00:03:29,100 --> 00:03:33,120
So let's check this out in HTML and CSS in order to really understand it.

47
00:03:34,090 --> 00:03:34,360
All right.

48
00:03:34,390 --> 00:03:36,670
Here I am back inside our code editor.

49
00:03:37,000 --> 00:03:41,560
Let's go ahead and delete some of the CSIS that we created from the previous lecture.

50
00:03:41,890 --> 00:03:43,330
And I'm also going to.

51
00:03:44,230 --> 00:03:44,770
Delete.

52
00:03:46,140 --> 00:03:51,450
The HTML code lets actually create the same situation we had previously in those slides, so I'm going

53
00:03:51,450 --> 00:03:58,950
to say above the div for a paragraph tag, then I'll create a div and inside this div I'll create some,

54
00:03:58,950 --> 00:04:00,450
Texas says inside the div.

55
00:04:02,080 --> 00:04:06,100
And then what I'll say here is create another paragraph that says.

56
00:04:07,200 --> 00:04:08,010
Below that, if.

57
00:04:09,070 --> 00:04:16,000
OK, so it looks like the same here in the output, but clearly we want to be able to add styling to

58
00:04:16,000 --> 00:04:17,079
each of these paragraphs.

59
00:04:17,290 --> 00:04:17,950
How can I do that?

60
00:04:18,399 --> 00:04:25,330
Well, I can make use of things like classes and IDs, so classes typically go with divs and we can't

61
00:04:25,330 --> 00:04:26,200
actually reuse them.

62
00:04:26,650 --> 00:04:31,870
So we're going to say class is equal to let's create a string here called my class.

63
00:04:32,560 --> 00:04:36,190
Now the question is, how do we actually refer to my class here?

64
00:04:36,580 --> 00:04:41,140
Previously, we were referring to elements just by their name, something like Div, and then I would

65
00:04:41,140 --> 00:04:44,110
say something like color for text.

66
00:04:45,110 --> 00:04:47,870
And maybe use Orange, for instance.

67
00:04:48,410 --> 00:04:54,890
OK, so that's one way I could do it, but if I want to only apply it to this specific div, so I'm

68
00:04:54,890 --> 00:05:02,480
actually going to create a div here, and let's also create a paragraph that says 2nd div.

69
00:05:02,780 --> 00:05:05,540
Notice the second div is orange as well.

70
00:05:06,050 --> 00:05:12,710
So maybe what I want to do is instead of using the div, I'll only use the class to tell CST, Are you

71
00:05:12,710 --> 00:05:13,610
using a class?

72
00:05:13,670 --> 00:05:20,390
Use a period first and then you type out the class name, which in our case was my class.

73
00:05:20,870 --> 00:05:25,130
Then you have your curly braces and you can assign the styling like color red.

74
00:05:26,010 --> 00:05:29,760
And note now, since I'm only referring to my class.

75
00:05:30,150 --> 00:05:36,780
Notice how only that first div paragraph and everything inside of that div is going to have that text

76
00:05:36,780 --> 00:05:42,120
color read, but it doesn't affect any of the other paragraphs or any of the other dibbs because I'm

77
00:05:42,120 --> 00:05:48,930
only referring to my class if I connect that class to this other div by saying something like class

78
00:05:49,440 --> 00:05:51,790
is equal to my class.

79
00:05:51,810 --> 00:05:54,060
You'll notice then it's actually connected.

80
00:05:54,480 --> 00:06:00,360
So that is how a class works and the difference between a class versus an ID that we're about to see

81
00:06:00,570 --> 00:06:02,520
is that class is expected.

82
00:06:02,940 --> 00:06:06,570
It's OK to use it multiple times on the same web page.

83
00:06:06,990 --> 00:06:12,690
If you want something that is a unique identifier for just a specific instance of an element.

84
00:06:12,960 --> 00:06:14,010
That's where you use it.

85
00:06:14,640 --> 00:06:18,540
So I can say something like ID and set this idea equal to one.

86
00:06:19,110 --> 00:06:25,680
Then if I want to actually apply styling to the ID element one, I come back to master's thesis.

87
00:06:26,610 --> 00:06:33,570
And then the next item I can do for an ID is you use a hashtag so ID selectors use hashtags and there

88
00:06:33,570 --> 00:06:35,910
are to single out an estimate element.

89
00:06:36,300 --> 00:06:38,460
So we named that ID one.

90
00:06:39,480 --> 00:06:43,500
And then here, I'll say color is blue.

91
00:06:45,230 --> 00:06:45,590
All right.

92
00:06:45,890 --> 00:06:54,830
So use hashtags for IDs and periods and the class name you can see now, I've specifically targeted

93
00:06:55,130 --> 00:06:55,850
that ID.

94
00:06:56,600 --> 00:07:00,650
And let's say we want to also have a specific target for below the div.

95
00:07:01,220 --> 00:07:03,630
I can give this an ID of two.

96
00:07:04,160 --> 00:07:05,600
Then I'll come back to the case.

97
00:07:07,080 --> 00:07:08,100
Say hashtag to.

98
00:07:09,300 --> 00:07:11,160
And let's give this a color green.

99
00:07:13,310 --> 00:07:20,120
OK, so I have above the div inside the div, below the div and second div, and even though these are

100
00:07:20,120 --> 00:07:25,490
all paragraph tags you can now see, I have a lot more flexibility in how I can style things.

101
00:07:25,850 --> 00:07:30,680
And let's imagine I wanted everything inside a div to have the color red.

102
00:07:31,040 --> 00:07:36,140
Well, then I can just put my paragraph tags inside the div so I can say also inside the div.

103
00:07:36,530 --> 00:07:41,120
And then if I wanted this to also have that effect, I can grab class again.

104
00:07:42,430 --> 00:07:45,310
Put it in here and now you can begin to see.

105
00:07:45,970 --> 00:07:52,510
Also in second, if you can begin to see how you can begin to organize containers in order to style

106
00:07:52,510 --> 00:07:53,470
only certain things.

107
00:07:53,980 --> 00:08:00,670
So the takeaway here is you use IEDs for a specific element and these should be unique.

108
00:08:00,670 --> 00:08:05,860
You should have two IEDs on the page that have the same name, even though it will technically still

109
00:08:05,860 --> 00:08:06,160
work.

110
00:08:06,370 --> 00:08:07,660
That's not really what they're meant for.

111
00:08:07,690 --> 00:08:11,800
They're just meant for unique identification of a specific element.

112
00:08:12,160 --> 00:08:15,280
If you do want something to be reused, you can use classes for that.

113
00:08:15,700 --> 00:08:18,040
Now, the classes need to be inside a div.

114
00:08:18,280 --> 00:08:19,360
No, not necessarily.

115
00:08:19,390 --> 00:08:21,640
You can have this be a class instead.

116
00:08:22,090 --> 00:08:28,780
So I could put this class attribute inside a paragraph as well, and it's going to work totally OK.

117
00:08:28,810 --> 00:08:31,870
So I can assign everything here with the class and notice.

118
00:08:31,870 --> 00:08:33,429
Now everything is read.

119
00:08:33,580 --> 00:08:37,600
And if I remove a class from something, you'll notice it turns black over here.

120
00:08:38,350 --> 00:08:43,419
So classes are OK to put in on a single element level.

121
00:08:43,690 --> 00:08:48,100
You'll typically see them inside a device because it just kind of works out that way that you get this

122
00:08:48,100 --> 00:08:48,970
nice little container.

123
00:08:49,210 --> 00:08:54,730
But you can then pass in styling codes, too, but it's totally up to you, and it depends on the situation.

124
00:08:55,330 --> 00:08:55,630
OK.

125
00:08:56,020 --> 00:08:58,660
So that's it for the idea of classes.

126
00:08:58,660 --> 00:09:02,890
And its main takeaway here is you can assign classes and IDs.

127
00:09:03,130 --> 00:09:08,800
Classes use a period in order for that selector to work IDs, use a hashtag in order for that selector

128
00:09:08,800 --> 00:09:09,130
to work.

129
00:09:09,700 --> 00:09:11,170
Thanks, and I'll see you at the next lecture.

