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
  • 700,868
  • 160
  • 1,392
  • 1,356
Thanh Trung
  • 3,566
  • 3
  • 31
  • 42

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
  • 153,751
  • 34
  • 298
  • 278
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).

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148