表格行上的 CSS 框阴影显示不正确

标签 css box-shadow

当悬停在表格行上时,我在表格行上添加了一个轻微的框阴影,这样它会更明显一些。它可以正常工作,但当我添加交替行颜色时,它会停止正确显示。

Here is a JSFiddle of the problem.

<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>

如您所见,当鼠标悬停在具有“alt”类的较深颜色的行上方时,框阴影会正常显示,但对于较浅颜色的行,它只会在行的顶部显示阴影,而不会在上方显示底端。从第 2 行和第 4 行删除“alt”类修复它,但以交替行颜色为代价。是什么导致了这种行为的发生,我该如何解决?

最佳答案

您可以通过将 transform: scale(1) 应用于悬停行来解决框阴影被其他表格行“隐藏”的问题:

.search-table table tbody tr:hover {
    box-shadow: 0px 0px 3px 0px #00000082;
    transform: scale(1);
}

关于表格行上的 CSS 框阴影显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55046056/

相关文章:

css - 在 IE 9 中没有任何显示?

javascript - html/css + MVC 的命名约定?

javascript - 使用 Onclick 事件将 div 移动到容器左侧的任何选项

css - 同一级别的多个元素上的框阴影但没有重叠?

jquery - 填满半圆动画

html - 给句子 CSS 的第一个词上色

css - 如何在所有四个面上应用 box-shadow?

css - 多个框阴影在 MSEdge 中不起作用

javascript - 对鼠标悬停在框阴影上使用react并更改该特定框阴影的颜色

html - 在内容滚动修复下方插入框阴影