【发布时间】:2021-11-15 13:41:52
【问题描述】:
我需要在我悬停的<td> 中显示红色背景色。例如,如果我将鼠标悬停在“Apple”上,那么所有<td> 中的“Apple”也应悬停在相同的颜色上。目前只能悬停一个<td>Apple</td>。
table {
margin: 2rem;
}
th, td {
border: 1px solid #333;
}
td:hover{
background-color:red
}
html {
font-size: 24px;
}
<h3>Table 1</h3>
<table>
<tr>
<th>Header 1.1</th>
<th>Header 1.2</th>
<th>Header 1.3</th>
</tr>
<tr>
<td>Apple</td>
<td>Orange</td>
<td>Lemon</td>
</tr>
<tr>
<td>Orange</td>
<td>Lemon</td>
<td>Apple</td>
</tr>
</table>
【问题讨论】:
-
请向我们展示您到目前为止的代码,您能否更清楚地解释一下需要什么?如果用户将鼠标悬停在仅包含 Apple 一词的 td 上,那么在其内容中某处包含该词的所有其他 td 也会突出显示,还是其他什么?
-
嗨,我已将代码放入 Codepen,如果用户将鼠标悬停在 Apple 上,则所有 Apple 都将突出显示,如果用户将鼠标悬停在 Lemon 上,则会突出显示所有 Lemon
-
@Muneeb K 我已经发布了我的答案,考虑一下
-
OP 你应该接受A Haworth's answer,因为它给出了详尽的解释。几乎所有其他答案都是纯代码答案。