CSS中条形表中悬停时的列和行突出显示 [英] Column and row highlight on hover in striped table in CSS
问题描述
我正在使用技巧,将鼠标悬停在 https://css-tricks.com/simple-css-row-column-highlighting/
I'm using trick for CSS only highlight of table column on hover from https://css-tricks.com/simple-css-row-column-highlighting/
它是完美的作品,但不适用于通过
It's work perfect, but not for striped table via
tr:nth-of-type(odd) {
background-color: #f0f0f0;
}
突出显示不适用于背景行中的上部和下部单元格。
Highlighting not apply to upper and bottom cells in rows with background.
在此处查看示例: http://jsfiddle.net/615avo4v/
请帮我解决没有JavaScript的问题。
Please, help me fix this issue without JavaScript.
请先感谢!
推荐答案
更改设置剥离背景的方式。
Change the way you set the stripped background.
使用另一个伪元素,这次在偶数行的第一个td上,并水平对齐。 (以及较低的z-index)。
Use another pseudo element, this time on the first td of the even rows, and aligned horizontally. (and with a lower z-index).
* {
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>
这篇关于CSS中条形表中悬停时的列和行突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!