CSS:已选中-更改< td& gt;背景 [英] CSS :checked - change <td> background

查看:43
本文介绍了CSS:已选中-更改< td& gt;背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CSS,可以根据< input type =是否选中了复选框"> ?

With CSS, is it possible to change the background-color of an entire <tr> based on whether or not an <input type="checkbox"> is checked?

<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>

推荐答案

目前不可以.正在指定此功能(请参见:has() ),但实际上在相当长的一段时间内不会公开提供给公众使用.

Not currently, no. This functionality is being specced (see :has()), but it won't actually be available for public use for quite some time.

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

注意:提供的示例根据当前的Editor's Draft是有效的,但是语法可能会更改,或者功能可能会在浏览器供应商甚至开始实施之前完全删除.

Note: The example provided is valid according to the current Editor's Draft, but the syntax may change or the functionality may be removed entirely before browser vendors even begin implementing it.

这篇关于CSS:已选中-更改&lt; td&amp; gt;背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆