簡體   English   中英

表格中的固定標題,html

[英]fixed headers in table, html

我有一張這樣的桌子

   <div style="overflow:auto">
   <table>
     <thead><tr style="position:fixed"><th></th></tr></thead>
   </table>
   </div>

現在我的問題是當我滾動div標題(即tr元素)被修復它工作正常,但當我滾動窗口的滾動條時,標題tr沒有固定在div內。 我沿着窗戶的滾動條移動......任何人都可以幫我找出解決方案

我不知道如果我的問題是對的,你可能會覺得這很有用http://fixedheadertable.com/

對不起,我試圖單獨使用CSS,但是沒有用,所以你需要一些Javascript。

<div style="overflow:auto; position:relative;"
    onscroll="document.getElementById('fixedtr').style.top = this.scrollTop+'px';">
  <table>
    <thead>
      <tr style="position:absolute; top:0; left:0" id="fixedtr">
        <th>Table header</th>
      </tr>
    </thead>

jsFiddle

這就是你想要的,對吧?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM