我在https://css-tricks.com/simple-css-row-column-highlighting/
悬停时使用的技巧仅用于CSS表格列的高亮显示这是完美的工作,但不适用于条纹表
select Country.Continent, Round(avg(City.Population),0)
from City, Country
where City.CountryCode = Country.Code
group by Country.Continent ;
突出显示不适用于具有背景的行中的上部和底部单元格。
请参阅此处的示例:http://jsfiddle.net/615avo4v/
请帮助我在没有JavaScript的情况下解决此问题。
提前致谢!
答案 0 :(得分:4)
更改设置剥离背景的方式。
使用另一个伪元素,这次是偶数行的第一个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>