如何“锁定” HTML 表格中的列?
我正在提取大量希望使用表格显示的表格数据。唯一需要注意的是,我希望能够“锁定”一些列(fname/lname/email),以便当用户水平滚动时,这些列始终保持“锁定”到位并且可见。我以前做过类似的事情,但那是在框架集时代,所以这种方法不再有效。
我正在考虑做一些聪明的事情,将桌子放在一起,但到目前为止,我还没有成功地完成这项工作。有人有什么聪明的建议吗?
我正在尝试做的一个完美的例子在这里: http://www.google.com/squared/search?q=world+领导者
I am pulling back a large amount of tabular data that I wish to display using a table. The only caveat is that I would like to be able to "lock" a few of the columns (fname/lname/email) so that when users scroll horizontally those columns always stay "locked" in place and are visible. I have done something similar to this before but that was back in the frameset days so that approach is no longer valid.
I was thinking about doing something clever with laying tables on top of each other but so far I have had no success with making this work. Anyone have any clever suggestions?
A perfect example of what I am trying to do is here:
http://www.google.com/squared/search?q=world+leaders
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的代码应该是不言自明的。您可以从 TBODY 添加/删除行,而 THEAD 保持完全静态。这就是 TBODY 和 THEAD 存在的目的;)
The code below should be pretty self-explanatory. You can add/remove rows from TBODY while THEAD remains perfectly static. This is what TBODY and THEAD exist for ;)
像这样的东西应该可以工作:
您将不得不稍微尝试一下,这样您就不会再有水平滚动条,但您明白了。
当然,这在IE7中不起作用。它可能在 8 中有效,但一如既往 YMMV。祝你好运。我希望这能让您朝着正确的方向开始。
Something like this should work:
You are going to have to play with it a little so that you don't have the horizontal scroll bar as well, but you get the idea.
Of course, this didn't work in IE7. It may work in 8, but as always YMMV. Good luck. I hope this gets you started in the right direction.
如果我正确理解你想要什么,你可以有一个容器 div ,其位置:相对,溢出:自动和固定宽度。在其中,您将想要锁定的部分与另一部分分开,例如两个不同的 div。包含“锁定”部分的 div 应该具有position:absolute和left:0。
这只是大局,但您应该能够通过这种方式完成您想要的事情。
If I understood correctly what you want, you can have a container div with position: relative, overflow: auto and fixed width. Inside of it, you separate the part you want to be locked, from the other one, into say, two different divs. The div containing the "locked" part should have position: absolute and left: 0.
It's just the big picture but you should be able to accomplish what you want this way.