12

谁能解释rowspancolspancolcolgroup?这些 W3C 是否有效且语义正确?这些在什么情况下有用?

4

3 回答 3

16

科尔斯潘

<table border="1">
  <tr>
    <th colspan="2">people are...</th>
  </tr>
  <tr>
    <td>monkeys</td>
    <td>donkeys</td>
  </tr>
</table>

行跨度

<table border="1">
  <tr>
    <th rowspan="2">monkeys are...</th>
    <td>... real monkeys</td>
  </tr>
  <tr>
    <td>... 'unreal' monkeys (people...)</td>
  </tr>
</table>

w3c

如您所见,这是用于连接表格单元格 - 因为有时这是必要的,所以它是有效的(RegDwights 链接将提供更多信息......)。

列/列组

colgroupcol用于为表中的每一行设置属性(因此您不必为每一行width="80"的第一行编写tdtr)):

<table border="1">
  <colgroup>
    <col width="80">
    <col width="100">
    <col width="320">
  </colgroup>
  <tr>
    <td>first line, first column</td>
    <td>first line, second column</td>
    <td>first line, third column</td>
  </tr>
  <!-- more table-lines... -->
</table>

您还可以对列进行分组,假设第一列和第二列应该得到with80,第三列应该得到 320:

<table border="1">
  <colgroup width="80" span="2"></colgroup>
  <colgroup width="320" span="1"></colgroup>
  <tr>
    <td>first line, first column</td>
    <td>first line, second column</td>
    <td>first line, third column</td>
  </tr>
  <!-- more table-lines... -->
</table>
于 2010-03-10T11:44:08.967 回答
5

是的,它们都是 W3C 推荐的。以下是文档的直接链接:

于 2010-03-10T11:36:32.140 回答
1

rowspan并且colspan是允许设计者“合并”单元格的属性——很像 Excel 中的相同命令(例如)。

colcolgroup允许设计人员将 css 应用于垂直列,而不必将 css 应用于列中的单个单元格。如果没有这些,这项任务将更加困难,因为 html 表是基于行的。

这四个都是有效的。

为了将来参考,请尝试http://reference.sitepoint.com/html

于 2010-03-10T11:36:40.100 回答