css HTML表与2行在其页脚,其中一个滚动另一个固定

w8rqjzmb  于 2023-11-19  发布在  其他
关注(0)|答案(1)|浏览(90)

我有一个HTML表,在其页脚2行,垂直和水平滚动工作正常,但我想保持页脚行固定之一(不滚动),以显示分页控件。
我想知道这是否可能只使用CSS。我已经尝试将displayposition属性更改为第二行,但没有预期的结果。

/* Center the grid container */

.container {
  width: 800px;
  height: 600px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Grid style */

#grid {
  margin-top: 25px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  max-width: 90%;
  min-width: 400px;
  overflow: hidden;
  height: auto;
  max-height: 473px;
}

/* Table size */

table {
  height: 388px;
  margin: 0 auto !important;
  display: block;
  overflow-x: auto;
  border-spacing: 0;
}

tbody {
  white-space: nowrap;
}

.caption {
  padding: 10px 10px 0px 10px;
  font-weight: bold;
  background: #b3b3b3;
  border-bottom: 1px solid #c8c6c6;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Columns style */

th {
  background: #b3b3b3 !important;
  vertical-align: bottom;
  text-transform: capitalize;
}

th.fixed {
  position: sticky;
  right: 0;
  z-index: 2;
}

td.fixed {
  position: sticky;
  right: 0;
  z-index: 1;
}

/* Header & Footer row style */

thead tr {
  position: sticky;
  top: 0;
  z-index: 2;
}

tfoot {
  position: sticky;
  z-index: 2;
  bottom: 0;
}

个字符

ht4b089n

ht4b089n1#

你可以做到这一点,但它是一种hacky地狱。
把页脚内容放在第一个td中,然后有一个空的td,它跨越了其他列。给予你的页脚td position:sticky; left:0;和(重要的是)white-space:nowrap,因为我们希望内容扩展到它的单元格之外,并粘在一边。
例如:

/* Center the grid container */

.container {
  width: 800px;
  height: 600px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Grid style */

#grid {
  margin-top: 25px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  max-width: 90%;
  min-width: 400px;
  overflow: hidden;
  height: auto;
  max-height: 473px;
}

/* Table size */

table {
  height: 388px;
  margin: 0 auto !important;
  display: block;
  overflow-x: auto;
  border-spacing: 0;
}

tbody {
  white-space: nowrap;
}

.caption {
  padding: 10px 10px 0px 10px;
  font-weight: bold;
  background: #b3b3b3;
  border-bottom: 1px solid #c8c6c6;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Columns style */

th {
  background: #b3b3b3 !important;
  vertical-align: bottom;
  text-transform: capitalize;
}

th.fixed {
  position: sticky;
  right: 0;
  z-index: 2;
}

td.fixed {
  position: sticky;
  right: 0;
  z-index: 1;
}

/* Header & Footer row style */

thead tr {
  position: sticky;
  top: 0;
  z-index: 2;
}

tfoot td.fixed {
  position: sticky;
  right: auto;
  left:0;
  z-index: 1;
  white-space:nowrap;
}

个字符
但是为什么要这么麻烦呢?您可以将分页内容放在table * 外部 * 的div中,而不是放在tfoot中。

相关问题