Class and ID

7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.53
List Price:  €65.14
You save:  €18.61
£39.80
List Price:  £55.73
You save:  £15.92
CA$68.29
List Price:  CA$95.61
You save:  CA$27.32
A$75.92
List Price:  A$106.30
You save:  A$30.37
S$67.59
List Price:  S$94.64
You save:  S$27.04
HK$390.62
List Price:  HK$546.91
You save:  HK$156.28
CHF 45.35
List Price:  CHF 63.50
You save:  CHF 18.14
NOK kr546.18
List Price:  NOK kr764.69
You save:  NOK kr218.51
DKK kr347.06
List Price:  DKK kr485.92
You save:  DKK kr138.85
NZ$83.56
List Price:  NZ$117
You save:  NZ$33.43
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,472.53
List Price:  ৳7,661.98
You save:  ৳2,189.45
₹4,170.94
List Price:  ₹5,839.65
You save:  ₹1,668.71
RM236.95
List Price:  RM331.75
You save:  RM94.80
₦61,737.65
List Price:  ₦86,437.65
You save:  ₦24,700
₨13,922.21
List Price:  ₨19,492.21
You save:  ₨5,570
฿1,839.58
List Price:  ฿2,575.56
You save:  ฿735.98
₺1,615.93
List Price:  ₺2,262.43
You save:  ₺646.50
B$255.52
List Price:  B$357.76
You save:  B$102.23
R925.67
List Price:  R1,296.01
You save:  R370.34
Лв90.98
List Price:  Лв127.38
You save:  Лв36.40
₩67,934.14
List Price:  ₩95,113.23
You save:  ₩27,179.09
₪185.78
List Price:  ₪260.11
You save:  ₪74.32
₱2,856.70
List Price:  ₱3,999.61
You save:  ₱1,142.91
¥7,653.44
List Price:  ¥10,715.43
You save:  ¥3,061.99
MX$846.70
List Price:  MX$1,185.45
You save:  MX$338.74
QR181.98
List Price:  QR254.79
You save:  QR72.81
P682.59
List Price:  P955.69
You save:  P273.09
KSh6,733.65
List Price:  KSh9,427.65
You save:  KSh2,694
E£2,396.77
List Price:  E£3,355.67
You save:  E£958.90
ብር2,849.43
List Price:  ብር3,989.43
You save:  ብር1,140
Kz41,866.62
List Price:  Kz58,616.62
You save:  Kz16,750
CLP$47,373.02
List Price:  CLP$66,326.02
You save:  CLP$18,953
CN¥361.77
List Price:  CN¥506.51
You save:  CN¥144.74
RD$2,892.40
List Price:  RD$4,049.59
You save:  RD$1,157.19
DA6,728.32
List Price:  DA9,420.19
You save:  DA2,691.86
FJ$112.64
List Price:  FJ$157.70
You save:  FJ$45.06
Q387.56
List Price:  Q542.62
You save:  Q155.05
GY$10,437.32
List Price:  GY$14,613.08
You save:  GY$4,175.76
ISK kr6,994.10
List Price:  ISK kr9,792.30
You save:  ISK kr2,798.20
DH504.29
List Price:  DH706.05
You save:  DH201.75
L885.56
List Price:  L1,239.86
You save:  L354.29
ден2,864.78
List Price:  ден4,010.92
You save:  ден1,146.14
MOP$401.51
List Price:  MOP$562.15
You save:  MOP$160.63
N$930.33
List Price:  N$1,302.54
You save:  N$372.20
C$1,836.63
List Price:  C$2,571.43
You save:  C$734.80
रु6,655.03
List Price:  रु9,317.58
You save:  रु2,662.54
S/187.71
List Price:  S/262.81
You save:  S/75.10
K191.79
List Price:  K268.53
You save:  K76.73
SAR187.49
List Price:  SAR262.51
You save:  SAR75.01
ZK1,342.57
List Price:  ZK1,879.71
You save:  ZK537.13
L231.55
List Price:  L324.19
You save:  L92.63
Kč1,163.97
List Price:  Kč1,629.65
You save:  Kč465.68
Ft18,122.66
List Price:  Ft25,373.17
You save:  Ft7,250.51
SEK kr541.93
List Price:  SEK kr758.75
You save:  SEK kr216.81
ARS$43,903.87
List Price:  ARS$61,468.94
You save:  ARS$17,565.06
Bs344.52
List Price:  Bs482.36
You save:  Bs137.83
COP$194,950.93
List Price:  COP$272,946.91
You save:  COP$77,995.97
₡25,444.18
List Price:  ₡35,623.88
You save:  ₡10,179.70
L1,237.75
List Price:  L1,732.95
You save:  L495.20
₲373,658.53
List Price:  ₲523,151.84
You save:  ₲149,493.31
$U1,916.38
List Price:  $U2,683.09
You save:  $U766.70
zł201.31
List Price:  zł281.85
You save:  zł80.54
Already have an account? Log In

Transcript

Hello, in this CSS Crash Course video, we're going to be looking at classes and IDs. Until now, when we've applied styling, we've either apply the inline solely only affects that particular element, or we've applied it to a particular element type. But the scenario might arise where you have less say to two days, I mean actually is rephrase that five days and two spans and instead of applying styling individually to each one of them in line, which again, you don't want to do inline styling, but let's just say that days an option, you can even do that. Or you can only apply style into div and span the Condor cell and apply it to two divs. And one span just using one piece of code and if you wanted to modify it, instead of having to do in every single place would only have to do in one place.

Unfortunately, using the techniques that we've done to moment your comp with classes and already you can classify It's something that isn't unique and you can apply it to several elements. And an ID is unique and it's a great way of referring to a particular element and object on the page for later use. So first of all, what we're going to do is just create a few elements a couple of four different those of them div, a div, div and another div. We're gonna put a div. I'm just going to put a span so you can see that we're going to be implementing them individually. So let's save that.

And now put some text in here. I'm just gonna literally do one, copy and paste this. It's just gonna take too long to do to do three diff for this. Ban to the Want to go one step back? Actually, I want to, I want to know that as well. So let's just put this on the fly.

Let's see what this looks like, refresh. So we've got a text. And like I said, the moment it only affects one, I mean, all elements of a particular type, what we're going to do is provide an ID. So you do ID as an attribute equals the unique name of this particular element. This is only unique on this page. So you could have two different pages, let's say homepage, bound page, unnecessarily.

If you have a description text, and the ID is called description text, you could have a description text already on the homepage and on the about page as well. So don't be unique to a particular page. It's good to know that I'm going to put yellow save that if I said that refresh, obviously it's not Don't anything because that's just an identifier and directly refer to a ID in CSS. You don't put yellow. You put hash, then the name of your ID. It is case sensitive.

So bear that in mind in here. I'm going yellow. Save that. Refresh. Oh, that's weird. What's happened here?

Why is it not showing up now? Don't think then this and save that refresh? Something I've done in here has messed this up. So I'm just gonna delete it. So that refresh No, no, no, unless it okay the scrolling this messed up. on my map summary.

So if I save that refresh as it sees change now, but only the actual element that I've applied this ID to. Now what if we want to apply read to several different elements, we can do that by putting a class. So a class is something they can use for multiple elements. Again, similar thing with the ID, a class can only be used within that page. So if I were to put a class of red, here, ignore being red. That's just the way Sublime is highlight, highlighting the colors for this HTML.

So imagine if I have red here, and that changes the color to red the color the actual text color to red, then on a separate page, I have a red on there. Oh, sorry, my bad. No, no, no, no, no, just ignore me. I don't know why the how I said No, yeah, the ID he was correct. Or I was saying he wasn't unique on that page, but the actual path, I mean, the ID can be used on the other page with the class because it's not you unique, this concept isn't valid at all. So that doesn't matter.

But the actual application, the actual property they changing can be used on a different page longer the it includes the style sheet as well, or the code in some form. So now what we're going to do is applies class again, so let's just click here, we're going to leave default as it is, and we're going to put it to span as well. So you can see applies to different elements. You don't put hash, you don't just put ready to put dot and dot mean the class dot read. And now what we're going to do is put color read, save the actually I'm gonna put that lowercase last, usually a standard to use first letter lowercase for stuff like classes and uppercase for stuff like ID. So this is a great way of identifying them by just skimming over.

Oh, save that refresh. And there you can see, it's modified all the elements that we applied our class of read to. And yeah, beyond that there isn't much out to show. If, for example, you wanted to apply several classes, you can apply several classes to a particular element or employ one ID but several classes you've ran, all you do is go to class, press space, in the new name of your class, so be something like it FOSS employ be one, and they just refer to a simple space again, hello, space again, got world if I save that refresh, he hasn't changed because I don't have any particular styling for this, this or this class, but as an extra test, I recommend Adding some classes that are or adding an extra classes some of these elements, so you can actually see the multiple classes. That's it for classes and IDs.

If you have any questions, feel free to post them on my free education platform, sonar learning.co.uk. We have provided all the source code from this series, so feel free to check that out. And as usual, thanks for watching, and I hope you have a great day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.