使 HTML 表格的列跨越所有列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19544037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make an HTML table's column span all the columns
提问by Water Cooler v2
I have an HTML table and the CSS property table-layout
is set to fixed
.
我有一个 HTML 表,CSS 属性table-layout
设置为fixed
.
I want one of the cells in the table, the only cell in a particular row, to span all the columns in the table, i.e to fill the entire width of the table.
我想要表格中的一个单元格,即特定行中的唯一单元格,跨越表格中的所有列,即填充表格的整个宽度。
When I use:
当我使用:
<td colspan = "0" id = "tdPager">
It works with FireFox v24 and IE 9 and above but does not work with Internet Explorer 8 or below and any version of Chrome.
它适用于 FireFox v24 和 IE 9 及更高版本,但不适用于 Internet Explorer 8 或更低版本以及任何版本的 Chrome。
How do I make the column span the entire table width in all browsers?
如何在所有浏览器中使列跨越整个表格宽度?
I have tried all -- setting the colspan to the values "*", "100%" and even a number higher than the total number of columns but it produces a horrid effect on all browsers. All the columns in the rest of the rows get really thin. I cannot set the colspan to a fixed number equal to the total number of columns because the number of columns is dynamic.
我已经尝试了所有 - 将 colspan 设置为值“*”、“100%”甚至高于列总数的数字,但它对所有浏览器产生了可怕的影响。其余行中的所有列都变得非常细。我无法将 colspan 设置为等于总列数的固定数,因为列数是动态的。
回答by Alex W
You are using it incorrectly by setting it to 0
.
通过将其设置为 ,您错误地使用了它0
。
You need to set the colspan
equal to the maximum number of columns that you have in any row of your table.
您需要将 设置为colspan
等于您在表格的任何行中拥有的最大列数。
So, if your table has 6 columns in row 5 and that is the most, then you would set colspan="6"
.
因此,如果您的表格在第 5 行中有 6 列,并且是最多的,那么您将设置colspan="6"
.
If the number of columns is dynamic, then you need to set the colspan
dynamically.
如果列数是动态的,则需要colspan
动态设置。
回答by shyam_
you can just set the maximum possible no for that many column wont be available in the table
您可以为表中不可用的许多列设置最大可能的编号
like if you have max 5 column, just set colspan="6" or even more.
就像如果您有最多 5 列,只需设置 colspan="6" 甚至更多。
回答by Kasun Raditha Rajapakse
you must specify how many columns you want to span eg: clospan ="3"
您必须指定要跨越的列数,例如:clospan ="3"
回答by Bruce Patin
colspan="100%"
seems to work well in IE 10, Firefox 26 and Chrome 31.
colspan="100%"
似乎在 IE 10、Firefox 26 和 Chrome 31 中运行良好。