具有固定标题和旋转列标题的表格
P粉762730205
P粉762730205 2024-04-03 08:50:32
[CSS3讨论组]

我有一个带有固定标题和固定第一列的表格。 我还想将列标题旋转 45 度。

固定标题需要设置背景颜色。但是,这会导致 45 度旋转标题出现问题,因为下一栏的背景与前一栏的文本重叠。以下是问题的示例:

.fixed_table {
  white-space: nowrap;
  margin: 0;
  border: none;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.fixed_table td,
.fixed_table th {
  padding: 5px;
}
.fixed_table thead th {
  padding: 5px;
  position: sticky;
  top: 0;
  z-index: 1;
  width: 25vw;
  background: #F8F9FA;
}
.fixed_table td {
  background: #F8F9FA;
  padding: 5px;
  text-align: center;
  border: 1px solid #ccc;
}

.fixed_table tbody th {
  text-align: left;
  position: relative;
}
.fixed_table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}
.fixed_table tbody th {
  position: sticky;
  left: 0;
  background: #F8F9FA;
  z-index: 1;
}

th.rotate {
  /* Something you can count on */
  height: 140px;
  white-space: nowrap;
}

th.rotate > div {
  transform: 
    /* Magic Numbers */
    translate(25px, 51px)
    /* 45 is really 360 - 45 */
    rotate(315deg);
  width: 30px;
}
th.rotate > div > span {
  border-bottom: 1px solid #ccc;
  padding: 5px 10px;
}
Activity 1
Activity 2
Activity 3
Activity 4
Activity 5
Activity 6
Activity 7
Activity 8
Activity 9
Activity 10
Employee 1 12 12 12 12 12 12 12 12 12 12
Employee 2 12 12 12 12 12 12 12 12 12 12
Employee 3 12 12 12 12 12 12 12 12 12 12
Employee 4 12 12 12 12 12 12 12 12 12 12
Employee 5 12 12 12 12 12 12 12 12 12 12
Employee 6 12 12 12 12 12 12 12 12 12 12
Employee 7 12 12 12 12 12 12 12 12 12 12
Employee 8 12 12 12 12 12 12 12 12 12 12
Employee 9 12 12 12 12 12 12 12 12 12 12
Employee 10 12 12 12 12 12 12 12 12 12 12
Employee 11 12 12 12 12 12 12 12 12 12 12
Employee 12 12 12 12 12 12 12 12 12 12 12
Employee 13 12 12 12 12 12 12 12 12 12 12
Employee 14 12 12 12 12 12 12 12 12 12 12
Employee 15 12 12 12 12 12 12 12 12 12 12

如果我不设置背景颜色,行会滚动列标题:

.fixed_table {
  white-space: nowrap;
  margin: 0;
  border: none;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.fixed_table td,
.fixed_table th {
  padding: 5px;
}
.fixed_table thead th {
  padding: 5px;
  position: sticky;
  top: 0;
  z-index: 1;
  width: 25vw;
  background: transparent;
}
.fixed_table td {
  background: #F8F9FA;
  padding: 5px;
  text-align: center;
  border: 1px solid #ccc;
}

.fixed_table tbody th {
  text-align: left;
  position: relative;
}
.fixed_table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}
.fixed_table tbody th {
  position: sticky;
  left: 0;
  background: #F8F9FA;
  z-index: 1;
}

th.rotate {
  /* Something you can count on */
  height: 140px;
  white-space: nowrap;
}

th.rotate > div {
  transform: 
    /* Magic Numbers */
    translate(25px, 51px)
    /* 45 is really 360 - 45 */
    rotate(315deg);
  width: 30px;
}
th.rotate > div > span {
  border-bottom: 1px solid #ccc;
  padding: 5px 10px;
}
Activity 1
Activity 2
Activity 3
Activity 4
Activity 5
Activity 6
Activity 7
Activity 8
Activity 9
Activity 10
Employee 1 12 12 12 12 12 12 12 12 12 12
Employee 2 12 12 12 12 12 12 12 12 12 12
Employee 3 12 12 12 12 12 12 12 12 12 12
Employee 4 12 12 12 12 12 12 12 12 12 12
Employee 5 12 12 12 12 12 12 12 12 12 12
Employee 6 12 12 12 12 12 12 12 12 12 12
Employee 7 12 12 12 12 12 12 12 12 12 12
Employee 8 12 12 12 12 12 12 12 12 12 12
Employee 9 12 12 12 12 12 12 12 12 12 12
Employee 10 12 12 12 12 12 12 12 12 12 12
Employee 11 12 12 12 12 12 12 12 12 12 12
Employee 12 12 12 12 12 12 12 12 12 12 12
Employee 13 12 12 12 12 12 12 12 12 12 12
Employee 14 12 12 12 12 12 12 12 12 12 12
Employee 15 12 12 12 12 12 12 12 12 12 12

是否有人有解决方案来 (a) 保持标题固定并且不显示在其后面向上滚动的行数据,以及 (b) 让所有 45 度旋转的标题仍然正确显示?

提前致谢!

P粉762730205
P粉762730205

全部回复(1)
P粉662802882

尝试以下代码:

.fixed_table thead th {
    padding: 5px;
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: white;
    width: 25vw;
    /* background: transparent; */
}

我希望这会有所帮助。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号