1

Supposing I have a HTML like this

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

Question: how can I select the label of a checked radio in this case?

BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
Thanh Trung
  • 3,114
  • 3
  • 25
  • 37

2 Answers2

2

What you are trying to achieve is not possible in CSS3.. if you want, you can wrap the elements inside a container, and position them either by floating, or by using position: absolute;

Demo (Not relevant as you've not provided any specific code, but I've shared a general example here)

div.wrap label {
    float: left;
}

.wrap input[type=radio]:checked + label {
    color: red;
}
Mr. Alien
  • 140,764
  • 31
  • 277
  • 265
1

In CSS3, there's currently no way to do that.

What you should do is add a class to your labels, then target that class.

For reference, they're looking to include this in the CSS 4 Specification which would use the notation:

!label > input[type="radio"]:only-child

But that's not supported by any browsers yet (as it isn't even finalised).

mattytommo
  • 52,879
  • 15
  • 115
  • 143