Frozen table header inside scrollable div

前端 未结 11 2126
Happy的楠姐
Happy的楠姐 2020-11-30 04:15

I\'ve three divs. Header, central and footer. There is a table in central div (gridview) which is almost always longer than outer div. So I\'ve made this div scrollable vert

11条回答
  •  一向
    一向 (楼主)
    2020-11-30 05:10

    Here is a basic solution using javascript:

    function position(table) {
        table.rows[0].style.position="absolute";
        table.rows[0].style.top="0px";
        table.style.marginTop = table.rows[0].clientHeight/1.2;
        var widths = Array();
        for(var i = 0; i < table.rows[0].cells.length; i++) {
            widths[i] = max(table.rows[0].cells[i].clientWidth, table.rows[1].cells[i].clientWidth);
        }
        for(var row = 0; row < table.rows.length; row++) {
            for(var col = 0; col < widths.length; col ++) {
                table.rows[row].cells[col].style.width = widths[col] + "px";
            }
        }
    }
    
    function max(num1, num2) { return (num1 > num2) ? num1 : num2; }
    

提交回复
热议问题