热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Chrome中仅支持CSS的粘性表标题

如何解决《Chrome中仅支持CSS的粘性表标题》经验,为你挑选了2个好方法。



1> Kirill Matro..:

position:sticky不适用于Chrome中的某些表元素(thead/tr).您可以将粘性移动到需要粘贴的tds/ths.像这样:

.table {
  thead tr:nth-child(1) th{
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
  }
}

这也行.

.table {
    position: sticky;
    top: 0;
    z-index: 10;
}

您可以将标题移动到单独的布局.例如:

1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4


值得注意的是,如果表包含在`overflow:auto`或`overflow-x:auto`的元素中,这将不起作用.如果在bootstrap的`.table-responsive`类中包装表,就会发生这种情况.
如果列的宽度相同,则单独的布局选项才可用

2> Tomsgu..:

对于那些仍在寻找解决方案并且对已接受的解决方案不满意的人.

1)在元素上使用粘性顶级类.

2)有自己的班级

th.sticky-header {
  position: sticky;
  top: 0;
  z-index: 10;
  /*To not have transparent background.
  background-color: white;*/
}


如果`thead`中有两个(或更多)标题行怎么办?
推荐阅读
author-avatar
lisen0001
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有