colspan(HTML属性)

tech2022-12-27  142

描述 (Description)

Just as the th element uses colspans, so can the td element to allow data to be shared across numerous columns in a table. The concept is best explained by comparing the example HTML above with the below table (where we indicate a person’s availability for Tuesday—when that person is free for the whole day—by spanning the cell across four time slots).

就像th元素使用colspans ,td元素也可以允许数据在表中的许多列之间共享。 通过将上面的示例HTML与下表进行比较,可以最好地解释这一概念(在下表中,我们将一个人分散在四个时隙中,表明该人在星期二有空,而该人全天都有空)。

When you’re introducing a colspan attribute, take care to ensure that each row is equivalent to the number of cells that would ordinary appear in the row. Some tables can become quite complicated with a mixture of colspan and rowspan attributes, and this is not something that you’re advised to hand-code—that’s just asking for trouble! It’s much better to use a WYSIWYG editor, such as Dreamweaver, MS Expression, or something similar, which will allow you to merge and unmerge cells very easily, and takes care of these attributes for you.

引入colspan属性时,请注意确保每一行都等于该行中普通显示的单元格数量。 某些表可能由于混合了colspan和rowspan属性而变得非常复杂,因此建议您不要手工编写代码,这只是自找麻烦! 最好使用WYSIWYG编辑器,例如Dreamweaver,MS Expression或类似的东西,它将使您非常容易地合并和取消合并单元格,并为您处理这些属性。

Note that when you use the rowspan attribute, you can’t span a cell beyond the boundary of its containing rowgroup (namely the thead, tfoot, or tbody elements). So if the tbody comprises ten rows, the rowspan of a cell that’s defined in the first row can’t have a value greater than “10”.

请注意,在使用rowspan属性时,不能将单元格跨到其包含rowgroup (即thead , tfoot或tbody元素)的边界之外。 因此,如果tbody包含十行,则在第一行中定义的单元格的行跨度不能具有大于“ 10”的值。

(Example)

This example shows an extract from a calendar, with a person’s availability apparently spanning the whole day, as shown in the above table:

此示例显示了日历的摘录,一个人的空闲时间显然跨越了一天,如上表所示:

<tr> <th scope="row">Tue</th> <td colspan="4">Free</td> </tr>

(Value)

This attribute takes a number, which should equal the number of cells that this single td should replace. There’s also a special value of "0", which should inform the browser to span the cell to the end of the current group of columns.

此属性采用一个数字,该数字应等于此单个td应该替换的单元数。 还有一个特殊值"0" ,它应该通知浏览器将单元格跨到当前列组的末尾。

翻译自: https://www.sitepoint.com/colspan-html-attribute/

最新回复(0)