在行悬停时将CSS样式应用于第一个表格单元格

3
我有一个表格行,其中包含两个单元格。当我悬停在该行上时,如何使只有第一个单元格的背景色更改?
#formTable tr:hover {
   background:red; // only want the first cell to change...
                   // ...this will do the whole row
}

1
你应该将你的解决方案发布为一个答案,然后接受它。 - James Montagne
2个回答

17

3
这只会改变第一行的第一个单元格:
#formTable tr:first-child:hover td:first-child{
    background-color: red;
}

这将改变任何行的第一个单元格:
#formTable tr:hover td:first-child{
    background-color: red;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接