具有滚动列组的固定宽度 HTML 表格 –是否可以?
我的一个朋友问了我一个我无法回答或弄清楚的问题。
问题是:他想要制作一个宽度为100%并且有很多列的HTML表格,其中第一个(或两个)应该始终可见,而其他的如果总宽度高于[表格宽度]则应该滚动(100%) 减去前两列的宽度]。正如他所说,实际上这应该类似于 MS Excel 中的 Frozen 列。
我尝试将这些列分组为 colgroup,并使用 overflow: auto
设置第二个 colgroup 的样式,但这不起作用。相反,表格只是水平增长,使整个页面滚动。
他自己提出的一个部分解决方案是实际上有三个表:一个作为容器,一个用于两个静态列,一个用于滚动列,并将后者放入一个 div 中。然而,这个解决方案又存在一个问题:为了使其工作,div 需要一个绝对 width
值(指定 width: 100%
只会使表格增长)。
有什么办法可以解决这个问题吗?
编辑:感谢您的回复,我已将链接传递给我的朋友,希望他找到最适合他的解决方案。
A friend of mine asked me a question that I couldn't answer or figure out yet.
The problem is: he wants to make an HTML table having width of 100% and many columns, of which the first one (or two) should be always visible, while others should scroll if their total width is higher than [width of the table (100%) minus width of the first two columns]. As he said, in effect this should be similar to Frozen columns in MS Excel.
I tried to group those columns into colgroups and style the second colgroup with overflow: auto
, but that doesn't work. Instead, the table just grows horizontally, making the whole page scroll.
A partial solution that he himself came up with was to actually have three tables: one as a container, one for the two static columns and one for scrolling columns, and put the latter into a div. However, this solution again has a problem: in order for it to work, the div needs an absolute width
value (specifying width: 100%
just makes the table grow).
Is there any way to solve this problem?
Edit: Thanks for both replies, I've passed the links over to my friend, hope he finds a solution that suits him best.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论