Reputation: 21998
Code will be like
<label for="bar">Baz: <input type="text" name="bar" id="bar" class="foo"/></label>
I would like to style the label how do I select with CSS?
Upvotes: 2
Views: 2404
Reputation: 6055
There is currently no way to select a parent element using css alone. This will be possible in the upcoming css 4 (Thanks andyB)
So you really have 2 other options:
Modify the html so that you have a handle on the parent so that you can style it.
Use javascript to select the parent based on the child's css/id/name attribute.
Upvotes: 2
Reputation: 5998
Like so:
label[for="bar"] { color: red; }
This will target the label for "bar". It's a CSS2.1 selector, and it works in everything except IE6.
See example on jsFiddle: http://jsfiddle.net/TheNix/kTwDN/
Upvotes: 0