2013-07-13 22 views
0

我有一個80行的表。我將如何使第一行絕對?嘗試加入如何使html表第一行'絕對'

position: absolute; 

到,但沒有工作。有沒有使用CSS或jQuery的呢?

<table> 
<thead> 
<tr> 
    <td style="position: absolute;"></td><td style="position: absolute;"></td> 
</tr> 
</thead> 
<tbody> 
<tr> 
    <td></td><td></td> 
</tr> 
<tr> 
    <td></td><td></td> 
</tr> 
</tbody> 
</table> 

編輯:對不起,我的意思是不固定的。我的壞

+0

FYI了''​​在''應該是一個''什麼 – ChelseaStats

+0

你想實現什麼?一個''的絕對定位是可能的(例如:http://jsfiddle.net/thfz5/),但我不知道你爲什麼想要這個... – user113215

+2

你也可以看看[這個jQuery插件](http://www.fixedheadertable.com/)。 – Stano

回答

3

我假設你正在尋找一種方法來讓你的第一行始終顯示在頂部,即使頁面滾動。 absolute不是這樣做的方式。想像position:absolute將您的元素「粘合」到頁面上的位置,然後如果頁面滾動 - 您的元素隨頁面滾動並跳出視圖。

如果您希望您的標頭無論如何都堅持到頂部 - 您需要涉及一些CSS技巧。

這裏是這種技術的example

最簡單的辦法是,當然,要使用position: fixedDemo

+1

請參閱[本](http://stackoverflow.com/q/1628265/2454376) – mishik

1

做這樣的:

table thead tr:first-child { 
    position: absolute; 
} 

只需使用first-child僞元素。

或者如@mishik所述,那麼您可能需要的是position: fixedposition: relative; top: 0;

0

如果您想要在標題保持原位的情況下滾動表格,您可以執行以下操作,但仍然存在列未對齊的問題,並且必須縮短標題以避免出現問題其他的滾動條:

<div style="position:relative;"> 
<div style="overflow: auto;"> 
    <table> 
    <thead style="position:absolute;"> 
    <!-- Header here --> 
    </thead> 
    <tbody> <!-- body here --> </tbody> 
    </table> 
</div> 
</div> 
相關問題