user1994660 user1994660 - 6 months ago 26
CSS Question

How can I change the color of label with * in text

I have labels like this

<label> User Type*: </label>

Now is there any way to change the color of label to red if text contains * in it only with CSS

All I can do is edit
. I can't use Javascript.

Answer Source

No, without javascript you won't be able to style only the *. what you will need to do is to put the * in its own element, and style that element.



<label> User Type<span>*</span>: </label>


label span { color: red; }

example fiddle:

EDIT: looks like i misread the question. No there's no way to do what you want. The easiest alternative would be to just add a class to the label.


<label class='required'>User Type*: </label>


label.required { color: red; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download