CSS: checked - change the <td> background

Using CSS, can I change the background-colorwhole <tr>based on whether a checkbox is checked <input type="checkbox">?

Example

<table>
 <!-- This is the row I want to change the background of... -->
 <tr>
  <td>
   <!-- ...when this is checked -->
   <input type="checkbox" name="cb1" id="cb1" />
  </td>
  <td>Something 1</td>
 </tr>
</table>
+3
source share
1 answer

Not at present. This functionality is specified ( see:has() ), but in fact it will not be available for public use for quite some time.

 /* Only matches TRs that contain checked INPUTs */
 tr:has(input:checked) {
  background:red;
 }

Note. The above example is valid in accordance with the current editorial draft, but the syntax may change or the functionality may be completely removed before the browser developers even begin to implement it.

+6
source

All Articles