weixin_43939111 2021-08-30 14:47 采纳率: 25%
浏览 194

bootstrap表格添加class="table-responsive",thead宽度auto,表头表身错位

设计要求表头固定表身滚动,按照网上的方案css是这样写的,表外包裹一个class="table-responsive"的div

thead,tbody tr{
    display:table;
    width:100%;
    table-layout: fixed;
}
tbody{
    display:block;
    height:280px;
    overflow-y: scroll;
}

这在pc端完全没问题,但是模拟移动端尺寸大小时,需要效果为tbody超280时竖向滚动,整个table超屏幕宽度横向滚动。
上述css放在移动端发现表头都紧凑的挤在一起,对字长的th简直就是灾难!然后我改成了如下css,内容是舒展开了但还是存在错位问题:

thead{
          width:auto;
}
tbody tr{
    width:100%;
}
thead,tbody tr{
         table-layout: fixed;
    display:table;
}
tbody{
    display:block;
    height:280px;
    overflow-y: scroll;
}

求解决方法

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 创建了问题 8月30日