ShellRox ShellRox - 5 months ago 14
CSS Question

How can i apply css stylesheet to single specific element?

I am new to web development, I have tried css stylesheet with simple HTML element and it worked well, when i specified element name:

label {
color: green;
}


this would be applied to all label tags, but is there any way to apply stylesheet to single element? For example: There are 2 labels, one is green and second is blue, How can this be achieved?

Answer

There's lots of ways to accomplish this. There's lots of css selectors like ID, classes... See css selectors reference

Best way to achieve what you want is to use classss. See classes

.red {
      color: red;
}
.blue {
      color: blue;
}
<label class="blue">
    I'm blue
</label>
<label class="red">
  I'm red
</label>