首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在tr悬停时只更改一个单元格

在tr悬停时只更改一个单元格
EN

Stack Overflow用户
提问于 2021-04-20 01:09:38
回答 1查看 90关注 0票数 0

我每排有5个细胞。我可以更改所有5个单元格的背景:

代码语言:javascript
复制
tr:hover {
   background: some_color;
} 

但我希望5号细胞是不同的颜色。需要使用css、js或jquery回答。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-20 01:16:42

您可以使用:nth-of-type pseudo class指定第五个单元格。

代码语言:javascript
复制
tr:hover td:nth-child(5) {
  background-color: some_color;
}

代码语言:javascript
复制
tbody tr:hover {
  background-color: salmon;
}

tbody tr:hover td:nth-of-type(5) {
  background-color: steelblue;
}
代码语言:javascript
复制
<table border="1">
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
      <th>Header 4</th>
      <th>Header 5</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Cell 1-1</td>
      <td>Cell 1-2</td>
      <td>Cell 1-3</td>
      <td>Cell 1-4</td>
      <td>Cell 1-5</td>
    </tr>
    <tr>
      <td>Cell 2-1</td>
      <td>Cell 2-2</td>
      <td>Cell 2-3</td>
      <td>Cell 2-4</td>
      <td>Cell 2-5</td>
    </tr>
    <tr>
      <td>Cell 3-1</td>
      <td>Cell 3-2</td>
      <td>Cell 3-3</td>
      <td>Cell 3-4</td>
      <td>Cell 3-5</td>
    </tr>
  </tbody>
</table>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67171164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档