Duncan Krebs
Duncan Krebs

Reputation: 3502

CSS Style assignment

I have this defined in an existing CSS sheet that I'm working with:

label.error-field

To assign this to an html element do I simply do class="error-field" or do I add the label to have it be class="label.error-field"?

Upvotes: 0

Views: 209

Answers (5)

zzzzBov
zzzzBov

Reputation: 179046

label.error-field will select an element label with a class of error-field

<label class="error-field">...</label>

Upvotes: 3

Homam
Homam

Reputation: 23841

Add it simply to the label. class="error-field".

Upvotes: 3

Jared Farrish
Jared Farrish

Reputation: 49188

This will only work on labels.

<label class="error-field">I'm an error label, yo ho ho</label>

The label. part is a CSS type (element) selector with a class (.) selector.

Upvotes: 3

Niklas
Niklas

Reputation: 30002

label.error-field is only applied to <label> elements with the class "error-field".

So if you want it on a label, then you'd just assign the class as "error-field", like this:

<label class="error-field">

Upvotes: 4

Alp
Alp

Reputation: 29739

This is the right way:

<label class="error-field">My Label</label>

Upvotes: 4

Related Questions