在PHP中动态滚动时修复html表

时间:2016-07-05 08:14:03

标签: php html css

我在php中有动态表,其中<tbody>内容从数据库中动态获取,我希望在滚动时修复<thead>,我的代码在静态html <tbody>中工作正常。

这是我的代码

<div class="data">
  <table>
      <thead>
        <tr>
          <th>Page Id</th>
          <th>User Id</th>
          <th>Page Title</th>
        </tr>
      </thead>
      <?php
        foreach($this->analysisL as $key => $value) {?>
      <tbody>
        <tr>
          <td><?php echo $value['daily_clicks']?></td>
          <td><?php echo $value['RDCL']?></td>
          <td><?php echo $value['SDCL']?></td>

        </tr>
      </tbody>
      <?php }?>
    </table>
  </div>

这是我的css

body{
font-family: sans-serif;
}

h1{
font-size: 2em;
}

p{
margin-top: 1em;
}
div{
padding: 0 50px
}

.data{
position: fixed;
top: 0;  
z-index: 0;
}
.content{
position: relative;
background: #fff; 
z-index: 1;
padding: 50px;
}

th,td{
width: 200px;
padding: 3px;
}

th{
background: #ccc;
}

我的目标是在滚动时使表头固定位置,并使用php循环从数据库中获取表体动态内容

1 个答案:

答案 0 :(得分:0)

我建议您使用'head fixer'js library(https://github.com/lai32290/TableHeadFixer) 快速简便的方法使桌头/脚固定。