0

I want to write css for the labels of checkboxes based on checkbox enabled/disabled. I know the following methods, but I'm not satisfied with these.

Method1:

label[for="something"] {
   /* woohoo! */
}
  • I want to write a generalized css. I do not want to repeat for every checkbox like above.

Method2:

input[type="checkbox"]:enabled+label{ font-weight: bold; } 
  • this one directly picks the sibling and is not based on "for". I want to pick the label specifically that is associated with the checkbox and leave it alone if the label is not 'for' that checkbox.

How can I apply css based on a label's "for" attribute?

4

1 回答 1

2

认为你在 :checked 伪类之后而不是 :enabled

input[type=checkbox]:checked + label {}

上面将在选中复选框类型的输入后选择一个标签,该标签是下一个兄弟

于 2015-07-28T13:12:18.717 回答