css - 表 tr 上的 z 索引位于全局叠加层上方

标签 css html-table z-index

我想将表格中的特定 tr 定位在全局叠加层上方。 我尝试了这段代码但没有成功:

HTML

<table>
  <tr class="tr-1">
    <td>test</td>
  </tr>  
  <tr class="tr-2">
    <td>test</td>
  </tr>
</table>
<div class="overlay"></div>

CSS

tr {
  background-color: white;
}

tr.tr-1 {
  position: relative;
  background-color: red;
  z-index: 20;
}

.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: black;
  opacity: .3;
  z-index: 10;
}

有什么想法吗?

这是一个jsfiddle

这是预期的结果:

enter image description here

最佳答案

tr 上的 display 属性设置为 block 将使图层位于叠加层之上。

tr {
  background-color: white;
}

tr.tr-1 {
  position: relative;
  background-color: red;
  z-index: 20;
  display:block;
}

.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: black;
  opacity: 1;
  display:block;
  z-index: 10;
}
<table>
  <tr class="tr-1">
    <td>test</td>
  </tr>  
  <tr class="tr-2">
    <td>test</td>
  </tr>
</table>

<div class="overlay"></div>

关于css - 表 tr 上的 z 索引位于全局叠加层上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46472600/

相关文章:

javascript - 使用 jQuery 在特定的 <td> 元素中选择 &lt;input&gt;

css - z-index 不适用于 CSS 下拉菜单

javascript - 属性 'addEvent' 的值为 null 或未定义,不是 Function 对象

css - 使用 Styled Components 为什么伪类似乎仍然可以在没有&符号的情况下工作?

html - Bootstrap 4 表格间距

javascript - 对齐动态头部和主体 - .Net MVC

reactjs - Semantic-UI-React Loading 组件后面的这些单选按钮的 z 索引是否不正确?

html - 悬停时 Chrome 中的 Z-Index 闪烁

jquery 突出显示和取消突出显示表行

html - Nav 使字体变粗