您可以使用jQuery循環遍歷每個tr和td,並增加包含tr的高度,每個tr的相對位置基於第一個的大小。它只適用於某些情況下沒有colspans/rowspans和填充可能會導致問題。
var table = $('table');
var cellHeight = $('td',table).first().height();
var cellWidth = $('td',table).first().width();
var runningTop = 0;
$('tr',table).each(function(i,row) {
var rowCells = $(this).find('td');
$(this).height(cellHeight*(rowCells.length))
rowCells.each(function(x,cell) {
$(cell).css({ "position": "relative","top":(cellHeight*x)+runningTop,"left": "-"+(cellWidth*(x))+"px" });
runningTop = runningTop+cellHeight;
});
});
需要工作,但這裏的想法http://jsfiddle.net/hPhRX/1/
的表不一樣,工作的小提琴。 'td'元素是列,'tr'元素是行。 –
@JamesDonnelly,我知道。這就是我問的原因。 – Nakilon
也許使用div而不是表格? –