Fix columns in horizontal scrolling

前端 未结 3 1898
情歌与酒
情歌与酒 2020-12-01 03:58

I am currently trying to fix my first column in a table when the user scrolls in the X-axis. I am using this structure:

3条回答
  •  攒了一身酷
    2020-12-01 04:22

    SOLVED

    http://jsfiddle.net/DJqPf/7/

    .table-wrapper { 
        overflow-x:scroll;
        overflow-y:visible;
        width:250px;
        margin-left: 120px;
    }
    td, th {
        padding: 5px 20px;
        width: 100px;
    }
    th:first-child {
        position: fixed;
        left: 5px
    }
    

    UPDATE

    $(function () {  
      $('.table-wrapper tr').each(function () {
        var tr = $(this),
            h = 0;
        tr.children().each(function () {
          var td = $(this),
              tdh = td.height();
          if (tdh > h) h = tdh;
        });
        tr.css({height: h + 'px'});
      });
    });
    body {
        position: relative;
    }
    .table-wrapper { 
        overflow-x:scroll;
        overflow-y:visible;
        width:200px;
        margin-left: 120px;
    }
    
    
    td, th {
        padding: 5px 20px;
        width: 100px;
    }
    tbody tr {
      
    }
    th:first-child {
        position: absolute;
        left: 5px
    }
    
    
    
    
      
      JS Bin
    
    
    

    SOME RANDOM TEXT

    Month Item 1 Item 2 Item 3 Item 4
    Jan is an awesome month 3163 3163 3163 3163
    Feb 3163 3163 3163 3163
    Mar 3163 3163 3163 3163
    Apr 3163 3163 3163 3163
    May 3163 3163 3163 3163
    Jun 3163 3163 3163 3163
    ... ... ... ... ...

提交回复
热议问题