Table colspan span all columns regardless of # of columns
我正在动态地在asp.net代码后面创建一个表,并且我希望有一个仅包含2个单元格的页脚行。 第一个应该跨越表1中的所有列。 除了手动跟踪表中的列数之外,还有其他方法可以让我将colspan设置为表1中所有列的数吗?
最好是HTML或CSS解决方案?
Colspan无法使用CSS完成。它是结构而不是样式,因此是纯HTML。
不,您不能将"除一个以外的所有内容"指定为colspan。最好的办法是
请参见HTML规范中的表格:
colspan = number [CN]
This attribute specifies the number of
columns spanned by the current cell.
The default value of this attribute is
one ("1"). The value zero ("0") means
that the cell spans all columns from
the current column to the last column
of the column group (COLGROUP )
in which the cell is defined.
但是基本上,这只是罐头马路而已,我不知道浏览器的支持是什么样的,因此它不一定能给您带来任何好处。
在生成HTML或使用Javascript时,您将需要知道列数。
抱歉,这不是HTML或CSS解决方案...我只是建议这样做,因为我认为没有可以跨浏览器/跨浏览器版本运行的HTML或CSS解决方案。
您可以将表转换为Asp:Table,然后使用第一行的Cells.Count ...
但这可能比跟踪您现在添加的列数要多。但是它并不依赖于浏览器支持,因为它们全都在后面的代码中。
1 | <tr><td colspan="100%">1000</td></tr> |
来自问题:Colspan所有列
在IE 7/8和Firefox 5中均可使用