在 HTML 中制作面向列的表格
我正在尝试找出一种方法,将表格放入网页中,其中的列包含行(图 2),而不是相反的方式(图 1)。
由于有 TR
标记,制作行包含列的表格很简单,但没有相应的 TC
标记来允许表格以相反的方式工作。
我确实找到了这个单一的提案< /a> 到 W3C,但没有得到回应,似乎没有任何进展。
显然,W3C 认为它不值得实施,因此我正在尝试找出解决方法或其他方法来完成同样的事情。
(通用解决方案是理想的,但在我目前的情况下,我试图有效适合一堆宽度恒定的图像。)
图 1: 三行,每行包含一些列:
图 2: 三列,每列包含一些行:
I’m trying to figure out a way to put a table in a web page in which the columns contain rows (figure 2) instead of the other way around (figure 1).
Making a table in which rows contain columns is simple because of the TR
tag, but there is no corresponding TC
tag to allow tables to work the other way around.
I did manage to find this one, single, proposal to the W3C, but it was not responded to and seems to have gone nowhere.
Obviously the W3C did not deem it worth implementing, so I am trying to figure out a work-around or something to accomplish the same thing.
(A general-purpose solution would be ideal, but in my current case, I'm trying to efficiently fit a bunch of images of constant width.)
Figure 1: Three rows, each containing some columns:
Figure 2: Three columns, each containing some rows:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,您可以使用通常的标记来实现此布局。但我不认为这就是你所追求的。您想要以不同的方式嵌套元素。
您可以使用 div 来实现此目的,并且末尾的标记与表标记一样经济。
CSS 类需要一些修改才能正确。编辑:我尝试了 jsfiddle ,但尺寸是静态的,所以它不是很灵活。
CSS 是
You can achieve this layout with the usual markup of course. But I don't think that's what you're after. You want to nest the elements differently.
You can use div to achieve this, and the markup at the end is just as economical as table markup.
The CSS classes would need some mucking around to get right though. EDIT: I had a go with jsfiddle, but the sizes are static, so it's not very flexible.
CSS is
我有点同意 husbas 的主表想法,除了我会用列表而不是嵌套表做一点不同的事情。我认为这取决于您想要表示的数据类型,或者您是否只是使用表格作为布局页面的方式。
I sort of agree with husbas's master table idea except I would do it a tiny bit differently with lists instead of nested tables. I think it depends on what type of data you're trying to represent or if you're simply using the table as a way to lay out the page.
您可以定义单行三列的主表。然后主表中的每一列都可以包含一个表(或任何其他 HTML 容器)。像这样的事情:
You can define a master table with single row and three columns. And then each column in the master table can contain a table (or any other HTML container) within. Something like this: