回答
你已经采取了一项任务,如果你成功了,将让你成为英雄。我尝试了这个和直接的事情 - 定位:固定; - >是不可能的。我不得不将所有的< 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