views:

37

answers:

2

I would like to select <label> elements that immediately preceed <input type="checkbox">

from the CSS guide

Adjacent sibling selectors have the following syntax: E1 + E2, where E2 is the subject of the selector.

But, unless I'm misunderstanding the spec I need a select where E1 is the subject not E2. I'm sure this must be available, what am I missing?

+1  A: 

Actually no, youre not missing anything (unless i have been for quite some time now as well) - you cant select a previous sibling with css2 selectors.

prodigitalson
A: 

I've never used it, but I understand from the link that you've provided that it should be done exactly like follows:

input[type='checkbox'] + label { color: Red }

This should work for the next HTML:

<input type='checkbox' id='chckTest' /><label>Test checkbox</label>

I don't have the possibility to check it now but I believe that the "Test checkbox" text will be red...

Michael Kessler