正常情况下,table上鼠标hover,我们可以实现tr行变色,那列呢?有没有可能实现列变色?
可以的。演示地址 http://codepen.io/rainyjune/p…
代码来自: https://css-/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
}
具体参考:
/vequjid/edi…