【问题标题】:Table header to stay fixed at the top when scrolling滚动时表格标题保持在顶部
【发布时间】:2018-06-30 02:15:31
【问题描述】:

我正在尝试设计一个 HTML 表格,其中标题在向下滚动时将固定在页面顶部,但它不起作用。下面是我的html代码....

<table align="center">
<?php               
$select = "SELECT * FROM register where r_bid='".$_SESSION["id"]."' order by `name` ";
$result = mysql_query($select) or die(mysql_error());
$res = mysql_query("select * from regi_balic where b_id='".$_SESSION["id"]."'");
$row1=mysql_fetch_array($res);
$i=1;
echo'<thead><tr align="center">
<th width=3%><font size=3><strong>No.</strong></font></th>
<th width=10%><font size=3><strong>IC</strong></font></th>
<th width=12%><font size=3><strong>Name</strong></font></th>
<th width=12%><font size=3><strong>Reference</strong></font></th>
<th width=2%><font size=3><strong>Age</strong></font></th>
<th width=12%><font size=3><strong>Occupatin</strong></font></th>
<th width=5%><font size=3><strong>Mobile No</strong></font></th>
<th width=2%><font size=3><strong>Delete</strong></font></th>
</tr></thead>';
while($row = mysql_fetch_array($result))
{   
echo '<tbody><tr>
<td width="3%" align="center" ><font size=3>'.$i.'</font></td>
<td width="10%"><font size=3>'.$row1['name'].'</font></td>
<td width="12%" align="left" ><font size=3>
<a href="edit_detail.phpid='.$row["r_id"].'
&cand_id='.$_SESSION["id"].'&email='.$row["email"].'">'.$row['name'].'</a></font></td>
<td width="12%" align="center" ><font size=3>'.$row['reference'].'</font></td>
<td width="2%" align="right" style="padding-right:8px" >
<fontsize=3>'.$row['age'].'</font></td>
<td width="12%" align="right" style="padding-right:8px"><font 
size=3>'.$row['occupation'].'</font></td>
<td width="5%" align="right"><font size=3>'.$row['mob_no'].'</font></td>
<td width="2%"><a href="process_del_client.php?id='.$row['r_id'].'" onClick="return  
ConfirmSubmit(\'Are You sure ?\')"><img src = "images/delete.png"></a></td>
</tr></tbody>';
$i++;
}
echo '</table></div></center>';                 
?>
</div>

这是我的 CSS:

.list {
height: 409px;
width: 80%;
overflow: scroll;
}

【问题讨论】:

  • 使广告 css 位置:固定/绝对。
  • 添加样式位置:为您的表头固定。
  • 我已经这样做了,但是tad正在覆盖第一行。
  • 头{位置:固定;宽度:78%; }
  • 我已将此添加到广告中

标签: php jquery css html-table


【解决方案1】:

这样的? http://jsbin.com/fekoyi/1/edit

table {
  height: 1000px; /* To force existence of a scrollbar. */
  background: yellow; /* To aid seeing boundaries. */
}

th {
  position: fixed; /* Fixes its position to the window. */
  top: 0; /* Sets that fixed position to stick to the top of the window. */
  width: 100%; /* Fills the width of the window; made it easier to see in your markup. */
  background: pink; /* To aid seeing boundaries. */
}

【讨论】:

  • 仍然面临同样的问题,现在thead停留在页面顶部,如果我试图将css样式设置为top:100px;到头,然后它再次覆盖第一行
  • 您的问题要求“一个 HTML 表格,其中标题在向下滚动时将固定在页面顶部。”但是现在您不想要一个“停留在页面顶部”的表头吗?你想把表格的标题放在哪里?
  • 我的意思是表头应该固定在它的位置,行应该向下滚动
猜你喜欢
  • 2020-07-21
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-18
  • 2010-12-05
相关资源
最近更新 更多