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

将CSS样式应用于行悬停的第一个表格单元格,css,hover,Css,Hover,我有一个有两个单元格的表格行。我如何使它在我将行悬停时,只有第一个表格单元格的背景改变颜色 #formTable tr:hover { background:red; // only want the first cell to change... // ...this will do the whole row } 这应该起作用: #formTable tr:hover td:first-child { background:red; }

我有一个有两个单元格的表格行。我如何使它在我将行悬停时,只有第一个表格单元格的背景改变颜色

#formTable tr:hover {
   background:red; // only want the first cell to change...
                   // ...this will do the whole row
}
这应该起作用:

#formTable tr:hover td:first-child {
   background:red;
}

:第一个子项:

这将仅更改第一行的第一个单元格:

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

#formTable tr:hover td:first-child{
    background-color: red;
}

您应该将您的解决方案作为答案发布,然后接受它。