当鼠标悬停在表格行上时,我在表格行上添加了一个轻微的框阴影,以便它更加明显。它按预期工作,但是当我添加交替行颜色时,它停止正确显示。
<div class="search-table">
<table>
<tbody>
<tr>
<td>A1</td>
<td>A2</td>
</tr>
<tr class="alt">
<td>B1</td>
<td>B2</td>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
</tr>
<tr class="alt">
<td>C1</td>
<td>C2</td>
</tr>
</tbody>
</table>
</div>
<style>
.search-table {
display: block;
background-color: #535353;
font: normal 12px/150% Arial, Helvetica, sans-serif;
overflow: hidden;
border: 1px solid #8C8C8C;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.search-table a {
color: #424242;
}
.search-table table {
border-collapse: collapse;
text-align: left;
width: 100%;
background-color: #ffffff;
}
.search-table table td, .search-table table th {
padding: 3px 10px;
}
.search-table table thead th {
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #8C8C8C), color-stop(1, #7D7D7D) );
background: -moz-linear-gradient( center top, #8C8C8C 5%, #7D7D7D 100% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8C8C8C', endColorstr='#7D7D7D');
background-color: #8C8C8C;
color: #FFFFFF;
font-size: 15px;
font-weight: bold;
border-left: 1px solid #A3A3A3;
}
.search-table table thead th:first-child {
border: none;
}
.search-table table tbody td {
color: #424242;
border-left: 1px solid #DBDBDB;
font-size: 1.25em;
font-weight: normal;
padding: 0.5em;
}
.search-table table tbody tr {
z-index: 0;
}
.search-table table tbody tr:hover {
box-shadow: 0px 0px 3px 0px #00000082;
z-index: 1;
}
.search-table table tbody tr.alt {
background: #EBEBEB;
color: #424242;
}
.search-table table tbody td:first-child {
border-left: none;
}
.search-table table tbody tr:last-child td {
border-bottom: none;
}
</style>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,当鼠标悬停在具有“alt”类的深色行上方时,框阴影会按预期显示,但对于浅色行,它仅在行的顶部显示阴影,而不是在底部显示阴影。从第二行和第四行中删除“alt”类可以修复此问题,但代价是交替行颜色。是什么导致了这种行为的发生,我该如何解决它?
transform: scale(1)您可以通过应用于悬停行来修复框阴影被其他表行“隐藏”的问题:
.search-table table tbody tr:hover {
box-shadow: 0px 0px 3px 0px #00000082;
transform: scale(1);
}
Run Code Online (Sandbox Code Playgroud)