1

I am trying make the text after input bold if input is checked but I am failing. I think my is not finding the text. I appreciate any help or hint.

input[type="radio"]:checked+ {
  font-weight: bold;
}
<label for="radio-foobar">
  <input type="radio" id="radio-3" value="3" />
  Hello world!
</label>
Derek Wang
  • 9,675
  • 4
  • 14
  • 36
Node.JS
  • 1,849
  • 3
  • 28
  • 86

2 Answers2

3

focus-within and a transition hack can approximate this. The transition is to make sure the style is kept even if you click outside.

label {
  font-weight: 400;
  transition:0s 999s;
}

label:focus-within {
  font-weight: 900;
  transition:0s;
}
<label for="radio-3">
  <input type="radio" id="radio-3" value="3" >
  Hello world!
</label>
Temani Afif
  • 180,975
  • 14
  • 166
  • 216
0

On html, it is needed to cover Hello World! into html tag like <span> and on CSS you can select that span next to checked input using + CSS selector.

input[type="radio"]:checked + span {
  font-weight: bold;
}
<label for="radio-foobar">
  <input type="radio" id="radio-3" value="3" />
  <span>Hello world!</span>
</label>
Derek Wang
  • 9,675
  • 4
  • 14
  • 36