0

I need to select a label of a checked checkbox. This would be super easy if the label was underneath the checkbox. One could use the + selector then.

But what about a structure like this:

<label>
    <input type="checkbox" checked>
</label>

Am I right that it turned impossible now to select the label of the checked input with pure CSS?

Seems odd to me because I like the above structure more.

sleepless
  • 1,551
  • 1
  • 15
  • 31
  • It didn't "turn" impossible. It always was. Not sure what you "liking" a structure more has anything to do with it. – BoltClock Apr 25 '15 at 15:05
  • You're right, my preferences have nothing to do with the question. "turned impossible" was related to the other approach where I'd put the label under the input. – sleepless Apr 25 '15 at 15:08

1 Answers1

0

Its only possible with javascript.

Fix your code:

<input type="checkbox" checked />
Olli Zi
  • 325
  • 2
  • 10
  • 1
    The only thing that could conceivably be "fixed" is the lack of a name and value attribute, and even those aren't required for the markup to validate and were thus probably left out for the sake of brevity. The `>` is fine. In fact, having `checked` and `/>` doesn't make much sense - you either have `checked>` as in HTML or `checked="checked" />` as in XHTML. (You *can* mix and match in HTML5, but that's not the point. You're claiming that something needs to be fixed when it doesn't.) – BoltClock Apr 25 '15 at 15:08