Make the html table <thead> fixed, and scrolling in the dynamic <tbody> in php

I have a dynamic table in php where the <tbody>content is dynamically fetched from the database, I want to make it <thead>fixed during scrolling, my code works fine in static html <tbody>.

Here is my code

<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>

Here is my 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;
}

My goal is to fix the fixed position of the table while scrolling and the contents of dynamically fetching the table body from the database using php loop

0
source share
1 answer

I recommend you use the 'head fixer' js library ( https://github.com/lai32290/TableHeadFixer ) a quick and easy way to fix the head / foot of the table.

0

Source: https://habr.com/ru/post/1685932/


All Articles