我想实现某种半透明颜色覆盖悬停在表格行上,我在这里创建了一个DEMO。悬停改变表格行背景颜色
但是我不希望文本以任何方式被改变,所以只是背景,我想让它成为一种覆盖的原因是我只是希望细胞稍微暗一点,而不是悬停时颜色相同。合理?
代码:
<table id="compTable" class="prTable">
<tr class="prTableHeader">
<th></th>
<th></th>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr class="prTableRow">
<td class="prExerVariNameTD blackColor">Squat</td>
<td class="prVerticalSpace"></td>
<td class="prTableCell" title="@finalDate">100</td>
<td class="prTableCell" title="@finalDate">100</td>
<td class="prTableCell" title="@finalDate">100</td>
</tr>
</table>
CSS
.prTableCell {
padding: 7px;
width: 60px;
text-align:center;
border:1px solid #e1e1e1;
cursor:default;
}
.prExerVariNameTD {
width: 200px;
border:1px solid #e1e1e1!important;
padding: 5px 5px 5px 10px;
background-color: white;
}
.prVerticalSpace {
width: 50px;
}
.rowHover {
/*background: rgba(204, 204, 204, 0.5);*/
opacity: 0.5;
}
脚本:
$(document).ready(function() {
$("table#compTable .prTableCell:even").css("background-color", "#eeeeee");
$("table#compTable .prTableCell:odd").css("background-color", "White");
$(".prTableRow").hover(function() {
$(this).toggleClass("rowHover");
});
});
只需使用CSS:'.prTableRow:nth-child(偶数):hover {background-color:#eee; } .prTableRow:nth-child(odd):hover {background-color:#fff; }' –
您的标题和您的代码在这里有点不同。你说你想改变悬停的行背景颜色,但是你的代码已经设置了表格单元格的背景颜色。 –
当我第一次尝试它时,只改变了我徘徊的单元格,然后它全部变成了一团糟:/ @MikeMcCaughan –