我有這張表,我想在盤旋時改變顏色,但當鏈接位於TD內時也會改變不同的顏色。如何用CSS中TD的元素覆蓋TR?
<table>
<tr>
<td>Hovering this part will make the whole TR bgcolor red</td>
<td>Hovering this part will make the whole TR bgcolor red</td>
<td>Hovering this part will make the whole TR bgcolor red</td>
</tr>
<tr>
<td>Hovering this part will make the whole TR bgcolor red</td>
<td>Hovering this part will make the whole TR bgcolor red</td>
<td>Hovering this part will make the whole TR bgcolor red</td>
</tr>
<tr>
<td>Hovering this part will make the whole TR bgcolor red</td>
<td>Hovering this part will make the whole TR bgcolor red</td>
<td>
<a>HOVERING THIS LINK WILL MAKE WHOLE TR BG COLOR BLUE</a>
</td>
</tr>
</table>
我試着在CSS
table tr:hover:not(table td a) {
background-color: red !important;
}
table tr:hover{
background-color: blue;
}
但我有沒有運氣。 這可能沒有使用JavaScript/JQuery的?
這是不可能單獨使用CSS,CSS既然不能選擇父元素 – Johannes
這可能最終成爲一個解決? https://jsfiddle.net/8h6u711v/3/ –