css鼠标经过table文字变色,有没有可能用css实现当table被鼠标hover的时候,table列变色?...

正常情况下,table上鼠标hover,我们可以实现tr行变色,那列呢?有没有可能实现列变色?

可以的。演示地址 http://codepen.io/rainyjune/p…

代码来自: https://css-tricks.com/row-an…

可以,每个td的位置一个下标index值,鼠标滑过哪个,让那个index的都变色

我觉得不可能,因为CSS没有父元素选择器。鼠标hover到td上以后,其他tr里的td里没办法获知这件事。

还是借助JS。

<table>

<colgroup>

<col/>

<col class="red"/>

<col/>

</colgroup>

<thead>

<tr>

<th>color 1</th>

<th>color 2</th>

<th>color 3</th>

</tr>

</thead>

<tbody>

<tr>

<th>grey</th>

<td>red</td>

<td>blue</td>

</tr>

<tr>

<th>grey</th>

<td>red</td>

<td>blue</td>

</tr>

</tbody>

</table>

.red {

background-color: red;

}

td,th{

border:1px solid #ddd

}

具体参考:

https://jsbin.com/vequjid/edi…

3431402c1bcafac7e7cfb291f3f55629.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值