【问题标题】:Fix the header of html table at top修复顶部的html表格的标题
【发布时间】:2015-05-05 12:38:24
【问题描述】:

我已经修复了this fiddle 中给出的 html 表的列。同样,我试图仅将表的标题行修复为,

var $table = $('.table');
var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');

$fixedColumn.find('tbody').remove();

$fixedColumn.find('thead th').each(function (i, elem) {
    $(this).width($table.find('tbody tr:first td:eq(' + i + ')').width());
});

this fiddle 中给出。但是标题没有固定。缺少什么?

【问题讨论】:

  • 它应该解决什么问题?所有列标题与正文中的相应列的宽度相同,因此没有任何反应。
  • 和第一个小提琴一样,前 3 列被冻结,我想修复垂直滚动时在第二个小提琴中冻结的标题。
  • 只需将“overflow-y:scroll”放在 标签中即可。不在你的整张桌子上。

标签: javascript jquery html html-table tableheader


【解决方案1】:

这个怎么样??

DEMO

   <tr class="fixed">
       <th>#</th>
       <th>Table heading</th>
       <th>Table heading</th>
       <th>Table heading</th>
       <th>Table heading</th>
       <th>Table heading</th>
       <th>Table heading</th>
   </tr>

css

.fixed
{
    position:fixed;
    background:gray;

}

如果你有兴趣也可以试试这个EXAMPLE!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 2012-01-30
    • 2018-02-27
    • 2017-04-11
    相关资源
    最近更新 更多