Re: CSS selector to better match label elements

Manuel Strehl skrev:
> Hello,
>
> I've been pondering a while over the following suggestion for a new
> selector and, to my surprise, still think it is a necessary tool that is
> missing.
>
> <label> elements are notoriously hard to select with CSS in any
> non-trivial mark-up structure, when the state of their control is to be
> taken into account. Consider these frequent cases, where it is not
> possible to reach the <label> element with CSS selectors, when the
> corresponding <input> state is relevant:
>
> 1. <label><input> Input inside label</label>
>
> 2. <tr>
>     <td><input></td>
>     <td><label>Good ol' tables</label></td>
>   </tr>
>
> 3. <label>Label before input</label><input>
>
> If you want to make the label react to the state of its associated
> control, you need to rely on JavaScript to generate classes to "listen"
> to. Only example (1) would be addressed by a parent selector
> <http://www.w3.org/TR/2011/WD-selectors4-20110929/#subject>, e.g.,
> `$label input`. Reference combinators
> <http://www.w3.org/TR/selectors4/#idref-combinators> only work the other
> way round, to address the control from its label: `label /for/ input`.
> Case (3) is the inverse of `input + label`.
>
> --SNIP--
>
> Manuel
>
>
There was an idea to introduce the exclamation mark in selectors as a
way to specify the subject. It was ultimately rejected . It would have
been of some help in this situation, since it let you use the /for/
syntax to select the label instead of the input.

I will leave it to more experienced people with better memory to explain
why it was rejected.

Received on Thursday, 30 April 2015 07:21:58 UTC