Fix multiple columns in html table (JQuery)

前端 未结 2 1164
野趣味
野趣味 2021-01-24 09:01

I am looking for a way to freeze first three columns in html table. Sample of table: http://jsfiddle.net/ee6reLug/


...
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 09:45

    Enclose the table in a div and set a margin-left say 15em. Also set overflow-x:scroll

    .outer { 
       overflow-x:scroll;  
       margin-left:15em; 
       overflow-y:visible;
    }
    

    Now for the first 3 columns have separate classes and set position:absolute and left to 0em, 5em and 10em respectively.

    .headcol1 {
        position:absolute; 
        width:5em;  
       left:0;
       top:auto;
    }
    
    .headcol2 {
       position:absolute; 
       width:5em;  
       left:5em;
       top:auto;  
    }
    
    .headcol3 {
       position:absolute; 
       width:5em; 
       left:10em;
       top:auto;
    }
    

    Demo here

    PS: I have some problems setting the column heights. If someone could fix that it will be helpful.

提交回复
热议问题