简体   繁体   English

如何在HTML表格的最后一行的底部保留空白

[英]How to leave a white space at the bottom of the last line of a HTML table

I have a HTML table that is dynamically filled with a Javascript/jQuery function. 我有一个用Javascript / jQuery函数动态填充的HTML表。 Sometimes the table contains 0 or 1 line, sometimes 800 lines. 有时表包含0或1行,有时包含800行。

Each line has a height of 15px. 每行的高度为15px。 The table must always have a height of 800px even if there isn't enough lines to fill it. 即使没有足够的行来填满表格,表格的高度也必须始终为800px。 The only way I found to keep the same height for each line is to append blank lines after the last line. 我发现每行保持相同高度的唯一方法是在最后一行之后添加空白行。 I don't like this solution because it makes the table very long and a useless scrollbar appears on the right. 我不喜欢这种解决方案,因为它会使表格变得很长,并且右侧会出现无用的滚动条。

I am using this plugin for my table : http://www.farinspace.com/jquery-scrollable-table-plugin/ It helps me to force my table height to 800px if there are 800 lines it makes the table scrollable. 我正在为我的桌子使用此插件: http : //www.farinspace.com/jquery-scrollable-table-plugin/如果有800行,它可以使我将桌子高度强制为800px,这使桌子可以滚动。

Is there a solution for me to not append 50 blank lines if my table only contains one line? 如果我的表仅包含一行,是否可以不添加50个空行?

I would suggest on document reeady function find the no of rows in your table and dynamically add the css height prop to the table . 我建议在文件重试功能中找到表中的行号,然后将css height prop动态添加到表中。

check this demo code : 检查此演示代码:

$(document).ready(function(){

  var numOfRows = $("#myTable > tbody > tr").length ;

  var eachLine = 15 ;

  var heightofTable = numOfRows * 15 ;

  $('#tableID').css('height',''+heightofTable +'px');

});

i think this can work . 我认为这可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM