html - 卡住 CSS 表格中的两列

标签 html css

我想在 CSS 中卡住前两列,所以我这样做了;

tbody th {
  position: -webkit-sticky; /* for Safari */
  position: sticky;
  left: 0;
  z-index: 999;
}

但这里第一列保持粘性,当第二列到达边缘时它变得粘性,否则它不会,我想让两者都粘性。

最佳答案

对于每个 <th>,您的 css 将粘贴位置设置为 0(左边缘) .因此,滚动时每一列都将保持在左边缘。

对于第一列,您的 css 没问题。但是改变<tbody> <th>到类名,所以它只适用于第一列

第二列应该是这样的

.SecondColumn {
  position: -webkit-sticky; /* for Safari */
  position: sticky;
  left: 100px;  /* This is the width of first column, so second will stick to the right edge of the first column */
  z-index: 999;
}

关于html - 卡住 CSS 表格中的两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55202669/

相关文章:

javascript - Onclick 函数在 <span> 中不起作用?

javascript - CSS水平表格单元格间距: how?

css - 如何同时设置HTML5视频的高度和宽度?

javascript - 如果选中/选中所有 2 维单选按钮,则启用按钮

css - 使用 CSS 设置按钮图像位置

css - 非插图显示可折叠设置太宽

html - Bootstrap : How to get a column with 100% the height of another column

html - html中的CSS定位

html - Css 将 <a> 悬停在 <td> 内

css - 粉丝页面上的Facebook Like Widget,可见区域外的评论区域