在窗口可调表格上寻找固定标题
我尝试到处寻找,但找不到解决我的问题的好方法。我希望创建一个带有固定标题的表格,在滚动表格的其余部分时保留该标题。问题是我还希望它能够在页面窗口调整时对齐。我已经能够获得固定的标题,并且在调整窗口时能够使列对齐,只是无法让两者一起工作。有没有一个脚本可以做到这一点?我尝试过fixedheadertable jquery、flexigrid、fixed-header-coffee、chromatable 和 floatyhead。这些都无法给我我正在寻找的解决方案。也许我做错了什么,但我有一个使用 theader、tbody 等的传统表格。我想避免将表格分成两个表格,因为它们似乎永远不会正确排列,但如果这是唯一的解决方案,我会拿走它。
请帮忙!
I have tried looking all over the place and couldn't find a good solution to my problem. I am looking to create a table with fixed headers that stay while scrolling the rest of the table. The problem is I also want it to be able to be aligned when the page window adjusts. I have been able to get fixed headers and have been able to get columns to align when I adjust the window, just haven't be able to get both to work together. Is there a script out there that can do this? I have tried fixedheadertable jquery, flexigrid, fixed-header-coffee, chromatable and floatyhead. None of these were able to give me the solution I am looking for. Maybe I am doing something wrong but I have a traditional table using theader, tbody, etc. I would like to avoid splitting up the table into two tables, because it seems they never line up properly but if that's the only solution, I'll take it.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以仅使用标准 HTML/CSS。具体来说,在 CSS 中利用 display/overflow/height ,在 HTML 中利用 thead/tbody 。 CSS 示例:
HTML 示例:
You can use just standard HTML/CSS. Specifically, utilize display/overflow/height in your CSS and thead/tbody in your HTML. Example CSS:
Example HTML:
试试这个答案,
它可以在 IE8、Firefox 和 Chrome 中运行。
样式
表
或尝试这个
Try this answer,
It is working in IE8, Firefox and Chrome..
Style
Table
or try this
这是一个渐进增强的解决方案,应该是跨浏览器兼容的,这要归功于 jQuery。
This is a progressive-enhancement solution that should be cross-browser compatible, thanks to jQuery.
我修改了内特巴尔的上述答案。前面的答案栏排列会变得拥挤。
样式
表表
I modified above answer by Nate Barr. In the previous answer column alignment will become congested.
Style sheet
Table
jQuery DataTables 可能不是您想要的,但是您研究过它吗?
数据表文档包括“FixedHeader”的特殊部分,因此您可以查看许多实现。
http://datatables.net/examples/
文档中的一些相关 DataTables 固定标头示例:
< a href="http://datatables.net/release-datatables/extras/FixedHeader/two_tables.html" rel="nofollow">http://datatables.net/release-datatables/extras/FixedHeader/two_tables.html
<块引用>
“以下示例显示了两个...表格,它们都启用了固定标题。页脚也是固定的...”
http://datatables.net/release-datatables/extras/FixedHeader/top_bottom_left_right.html
<块引用>
“此示例展示了如何使固定标题看起来更像电子表格应用程序。”
jQuery DataTables may not be quite what you're looking for, but have you looked into it?
The datatables documentation includes a special section for "FixedHeader", so you have a number of implementations you can review.
http://datatables.net/examples/
Some relevant DataTables Fixed header examples from the documentation:
http://datatables.net/release-datatables/extras/FixedHeader/two_tables.html
http://datatables.net/release-datatables/extras/FixedHeader/top_bottom_left_right.html