Table with sticky header and resizable columns without using JQuery

后端 未结 4 2123
梦谈多话
梦谈多话 2021-02-13 10:44

All the solutions I\'ve seen to make a table with a sticky header and resizable columns seems to be using Jquery. I want a plain old solution using CSS only if possible. If CSS

4条回答
  •  情深已故
    2021-02-13 11:18

    The only thing you really need is position: sticky; on the header th. This combined with your resize: horizontal will fix your issue if I understand your question right.

    table {
      display: block;
      background-color: cyan;
      height: 200px !important;
      overflow-y: scroll;
    }
    
    thead th {
      position: sticky;
      top: 0;
      background: white;
      z-index: 10;
    }
    
    th,
    td {
      resize: horizontal;
      overflow: auto;
      min-width: 25px;
    }
    
    td {
      font-size: 1.45vmin;
    }
    
    tbody {
      height: 30px !important;
      background-color: green;
      width: 100%;
    }
    header1 header2 header3 header4 header5
    1 2 3 4 5
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1

提交回复
热议问题