Any way to synchronize table column widths with HTML + CSS?

前端 未结 9 1319
花落未央
花落未央 2020-12-24 05:05

I have a number of tables with the same columns and it would look a lot nicer if they shared the same column widths. Is such a thing possible? Putting them in the same tab

9条回答
  •  甜味超标
    2020-12-24 05:59

    Luis Siquot answer is the one I used. However instead of using clientWidth, you should use jquery width() function to normalize widths between browsers, and to not calculate padding. Using clientWidth would result in the table cells expanding on ajaxpostbacks because of the padding (if padding used in the TD's). So, correct code using Luis Siquot's answer would be to replace

    var cell = $(this)[0].rows[0].cells[j];
           if(!cellWidths[j] || cellWidths[j] < cell.clientWidth) cellWidths[j] = cell.clientWidth;
    

    with

    var cell = $($(this)[0].rows[0].cells[j]);
                if (!cellWidths[j] || cellWidths[j] < cell.width()) cellWidths[j] = cell.width();   
    

提交回复
热议问题