Is there a possible way to target the label for an input in css3? For example I tried this method –
input[type="text"]:focus label:target {
color:orange !important;
}
Doesn’t seem to work, just wondering or is this a job for jquery only?
Thanks!
The
:targetpseudo-class doesn’t do what you think it does, andlabelcan never exist as a descendant ofinput, so that won’t work.If you’re trying to refer to a
labelwhich is associated with aninputeither by parentage or theforattribute, that’s not possible with CSS3. You can only refer to thelabelif it’s a sibling that follows theinput, with either one of these:If the
labelis an ancestor, preceding sibling or completely elsewhere, you’ll need to use jQuery to traverse the DOM and locate it.