Halst Halst - 1 year ago 126
CSS Question

Highlight label if checkbox is checked

Is there a non-javascript way of changing the color of a label when the corresponding checkbox is checked?

Answer Source

If you have

  <input type="checkbox" class="check-with-label" id="idinput" />
  <label class="label-for-check" for="idinput">My Label</label>

you can do

.check-with-label:checked + .label-for-check {
  font-weight: bold;

See this working. Note that this won't work in non-modern browsers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download