回答
你已經採取了一項任務,如果你成功了,將讓你成爲英雄。我嘗試了這個和直接的事情 - 定位:固定; - >是不可能的。我不得不將所有的< thead>複製到一個新的對象中。但是當你這樣做時,< th元素的水平間距全部消失,所以標題不再與< td> s一致。我結束了這樣的事情:
首先,放棄ie6和ie7。這些人沒有希望。
使表,一個在身體看不見的兩個副本和< THEAD>是可見的,並在它的反之亦然其他。
給z-index:1;到可見的< thead表中。
給z-index:0;到可見的< tbody>的表格。
與水平滾動交易,但直到你找到後onScroll不是IE8的事件(更不用說IE6),所以,你必須採取的setInterval打破每隔十分之一秒左右只是在ie8中處理滾動< thead> left和right。
這會給你一個兩軸無限滾動的表體,只有一個表頭可以在X軸上滾動。在FF,Chrome和Safari中相當有用。但在ie8中搖搖欲墜。一個真正的皮塔餅。
祝你好運,並請寫,如果你得到這個工作!
我最終使用的第二表和在
一個 | 兩個 |
---|
@JNK,對你有好處!而且,能夠認識到「足夠好」的關鍵點非常出色,實際上,這一切都已經完成。 – 2011-03-18 10:25:40
老實說這個答案似乎不對。我明白你的意思,但即使如下面的鏈接所示,它肯定是可能的。技巧是明確設置tbody的高度,而不是試圖讓它從父元素繼承。有一個理想的方法可以明確地設置tbody的高度,只需創建一個jQuery插件,將tbody的高度設置爲容器的高度減去thead的高度。 – teh1 2013-05-14 22:29:02
只有Firefox和IE6-7瀏覽器都支持內置<tbody>
滾動:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Scrolling</title>
<style type="text/css">
div.content
{
border: #000000 1px solid;
height: 400px;
overflow-y: auto;
width: 800px;
}
.fixedHeader
{
white-space: nowrap;
}
.fixedHeader tr
{
height: auto;
position: relative;
}
.fixedHeader tr td
{
background-color: #778899;
border: #000000 1px solid;
text-align: center;
}
tbody.scrollContent
{
overflow-x: hidden;
overflow-y: auto;
height: 370px;
}
.scrollContent tr td
{
background-color: #C0C0C0;
border: #000000 1px solid;
padding-right: 22px;
vertical-align: top;
}
</style>
<!--[if IE]>
<style type=text/css>
div.content
{
overflow-x: hidden;
overflow-y: auto;
}
</style>
<![endif]-->
</head>
<body>
<div>
<div class="content">
<table cellspacing="0">
<thead class="fixedHeader">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</thead>
<tbody class="scrollContent">
<tr>
<td>Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. Pages with tabs are preferred for a standard user interface, and pages without tabs are preferred for a wizard. If tabs are omitted, you must provide a way of moving through the pages. For instance, Back and Next buttons can be implemented. Pages can be displayed either with or without tabs. Pages with tabs are preferred for a standard user interface, and pages without tabs are preferred for a wizard. If tabs are omitted, you must provide a way of moving through the pages. For instance, Back and Next buttons can be implemented. Pages can be displayed either with or without tabs. Pages with tabs are preferred for a standard user interface, and pages without tabs are preferred for a wizard. If tabs are omitted, you must provide a way of moving through the pages. For instance, Back and Next buttons can be implemented.</td>
<td>Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. </td>
<td>Pages can be displayed either with or without tabs. </td>
<td>Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. Pages can be displayed either with or without tabs. Pages with tabs are preferred for a standard user interface, and pages without tabs are preferred for a wizard. If tabs are omitted, you must provide a way of moving through the pages. For instance, Back and Next buttons can be implemented. Pages can be displayed either with or without tabs. Pages with tabs are preferred for a standard user interface, and pages without tabs are preferred for a wizard. If tabs are omitted, you must provide a way of moving through the pages. For instance, Back and Next buttons can be implemented. Pages can be displayed either with or without tabs. Pages with tabs are preferred for a standard user interface, and pages without tabs are preferred for a wizard. If tabs are omitted, you must provide a way of moving through the pages. For instance, Back and Next buttons can be implemented.</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
在WinXP上的Opera 11.x中也可以使用。 – stealthyninja 2011-03-17 21:31:31
如果這樣做我會...我會......好吧,我會流淚純粹的快樂。 – 2011-03-17 21:46:04
IE根本不支持它。基於Webkit的瀏覽器也沒有。只有FF2/3和某些歌劇確實支持它。然而,新的FF4將[不](https://developer.mozilla.org/En/Firefox_4_for_developers#Miscellaneous_CSS.c2.a0changes)支持它。這不是由W3指定的。 – BalusC 2011-03-17 21:57:23
這工作,把它恰好是我的網站:
#news_box {
overflow: scroll;
overflow-x: hidden;
}
編輯: 我也剛剛發現這個有一個很好的例子:
http://www.imaputz.com/cssStuff/bigFourVersion.html
這裏的另一個很好的文章就可以了:
http://www.scientificpsychic.com/blogentries/html-and-css-scrolling-table-with-fixed-heading.html
但在這兩頁上,整個表格 - 包括thead - 直接從頁。是的,如果你只滾動表體,它的效果很好。但是,如果表格是真實的,真實的,真實的,真正的廣泛的,我想使用頁面滾動條,同時始終保持頁眉可見。當然,只是imo。 – 2011-03-17 22:09:32
嘗試在ie7或ie8上打開這一個,如果它從那裏工作,那將是一個奇蹟。 :) – 2011-11-17 04:56:05
試試這個:http://stackoverflow.com/a/21250481/2837412 – 2014-01-21 06:13:07
這裏是解決方案,
表固定標題和表內的內容可以滾動。
HTML部分
<div class="table_wrapper">
<div class="header">
<div class="head1">Left</div>
<div class="head2">Center</div>
<div class="head3">Right Column</div>
</div>
<div class="tbody">
<table>
<tbody><tr><td class="td1">1</td><td class="td2">2</td><td class="td3">3</td></tr>
<tr><td class="td1">1</td><td>2</td><td class="td3">3</td></tr>
<tr><td class="td1">2</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">3</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
<tr><td class="td1">first</td><td>second</td><td class="td3">third</td></tr>
</tbody></table>
</div>
</div>
CSS部分
.table_wrapper {background:tomato;border:1px double olive;float:left;}
.tbody{height:80px;overflow-y:auto;width:400px;background:yellow;}
table{border-collapse:collapse; width:100%;}
td{border-right:1px solid red;border-bottom:1px solid red;padding:1px 5px;}
.td3{border-right-width:0;}
.header{ width:400px;background:DodgerBlue;border-bottom:1px solid red;}
.header div{padding:1px 5px;float:left;border-right:1px solid orange;}
.header .head3{float:none;border-right-width:0;}
.head3 span{padding-left:5px;}
.td1{width:100px;}
.td2{width:140px;}
.header .head1{width:100px;}
.header .head2{width:140px;}
這是通過放棄自動調整列寬到內容的大小來實現的。 – 2014-06-18 12:56:22
這個簡單的CSS應該做的伎倆:如果你需要它
table.table-scroll-body {
position: relative;
height: 200px; }
table.table-scroll-body tbody {
position: absolute;
width: 100%;
max-height: 150px;
overflow: auto; }
和HTML ..
<table class="table-scroll-body">
<thead>
<th>Header 1</th>
<th>Header 2</th>
</thead>
<tbody>
<tr>
<td>Some content..</td>
<td>Some content..</td>
</tr>
<tr>
<td>Some content..</td>
<td>Some content..</td>
</tr>
<tr>
<td>Some content..</td>
<td>Some content..</td>
</tr>
</tbody>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
table
{
width: 320px;
display: block;
border:solid black 1px;
}
thead
{
display: inline-block;
width: 100%;
height: 20px;
}
tbody
{
height: 200px;
display: inline-block;
width: 100%;
overflow: auto;
}
th, td
{
width: 100px;
text-align:center;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
</tbody>
</table>
</body>
</html>
妖異astrandr的答案..這裏是我做到了,用他們的例子:
CSS:
.transactHistory table
{
width: 320px;
display: block;
}
.transactHistory thead
{
display: inline-block;
}
.transactHistory tbody
{
height: 133px;
display: inline-block;
width: 100%;
overflow: auto;
}
.transactHistory th
{
width: 100px;
text-align:center;
}
.transactHistory tr
{
width: 100px;
text-align:center;
}
.transactHistory td
{
width: 100px;
text-align:center;
}
表:
<div class="transactHistory">
(..table code)
</div>
- 1. 滾動<textarea>在iPhone
- 2. 替換<a>與<label> jquery動畫滾動
- 3. 使用Javascript自動滾動<textarea>
- 4. std ::可選<std :: reference_wrapper <T>> - 可以嗎?
- 5. 當用戶滾動<section> s時,可以更改背景顏色嗎?
- 6. React Native <ScrollView>持久滾動條
- 7. 滾動型setOverScrollMode置換API <9
- 8. <asp:CheckBoxList>上的滾動條?
- 9. 如何隱藏滾動條<select>
- 10. ListView在API上嵌套滾動<21
- 11. Ionic 2 <ion-content>禁用滾動
- 12. IE 8不滾動到#id <tr>
- 13. 關於滾動條在<iframe>
- 14. 在<article>中,<figure>可以在<header>之內嗎?
- 15. 我可以創建一個清單<Class<T>>嗎?
- 16. 我可以在<i>標籤內放置<img>嗎?
- 17. 爲原始類型重載operator <<。那可能嗎?
- 18. 可以<table>是<form>的孩子嗎?
- 19. JQuery UI Resizable <table>和固定高度可滾動
- 20. 當滾動<code>ListView</code>時,無法隱藏帶動畫的工具欄滾動ListView
- 21. NestedScrollView與RecyclerView不<code>RecyclerView</code>在它不滾動</p> <p>我試圖在這個論壇上討論的所有選項..滾動
- 22. IList <IWebElement>可以使用PageObject嗎?
- 23. 可以檢查雙「d <0」嗎?
- 24. 獲取<T>類 - 可能嗎?
- 25. <aui:input>可用於雙值嗎?
- 26. 風格<html>標籤可以嗎?
- 27. $ _POST [$ row ['field'] < - 這可能嗎?
- 28. 嵌套<form>可能嗎?
- 29. 我可以驗證<marquee>嗎?
- 30. 我可以將Iterator <Item = io :: Result <u8>>轉換爲io :: Result <Vec<u8>>嗎?
請參閱 http://stackoverflow.com/questions/1 30564/i-need-my-html-tables-body-to-scroll-and-its-head-to-stay-put – Santhanakumar 2012-12-02 09:55:02