更改設置剝離背景的方式。
使用另一個僞元素,這次是偶數行的第一個td,並水平對齊。 (並且具有較低的z-索引)。
* {
margin: 0;
padding: 0;
}
table {
width: 100%;
border-spacing: 0;
color: #212121;
text-align: left;
overflow: hidden;
}
table>tbody>tr>td {
padding: 10px;
font-size: 14px;
position: relative;
}
table>tbody>tr:hover {
padding: 20px;
background-color: #ffa !important;
}
tr:nth-child(even) td:first-child::before {
content: "";
position: absolute;
background-color: lightgreen;
top: 0;
left: -5000px;
width: 10000px;
height: 100%;
z-index: -10;
}
td:hover::after {
content: "";
position: absolute;
background-color: #ffa;
left: 0;
top: -5000px;
height: 10000px;
width: 100%;
z-index: -1;
}
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
<td>col8</td>
</tr>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
<td>col8</td>
</tr>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
<td>col8</td>
</tr>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
<td>col8</td>
</tr>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
<td>col8</td>
</tr>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
<td>col8</td>
</tr>
</table>
做你想做的僅強調該列項或整排當懸停 –
不......不會列高亮由坐在後面的一個僞元素來完成表本身。 JS將是這裏最好的選擇 –
@dnapierata檢查問題......他已經鏈接了該文章。 –