【问题标题】:make html table <thead> fixed while scroll in dynamic <tbody> in php在 php 中滚动动态 <tbody> 时修复 html table <thead>
【发布时间】:2016-07-05 08:14:03
【问题描述】:

我在 php 中有动态表,其中 &lt;tbody&gt; 内容从数据库动态获取,我想在滚动时固定 &lt;thead&gt;,我的代码在静态 html &lt;tbody&gt; 中工作正常。

这是我的代码

<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 循环从数据库中动态获取表体的内容

【问题讨论】:

标签: php html css


【解决方案1】:

我建议你使用'head fixer' js 库 (https://github.com/lai32290/TableHeadFixer) 快速简便地固定桌头/桌脚。

【讨论】:

    猜你喜欢
    • 2012-10-06
    • 1970-01-01
    • 2018-05-23
    • 2011-07-17
    • 2020-12-10
    • 2015-06-20
    • 2011-04-30
    • 2014-10-06
    • 2021-06-12
    相关资源
    最近更新 更多