请解释 rowspan 和 colspan、col 和 colgroup

发布于 2024-08-24 13:23:26 字数 121 浏览 2 评论 0原文

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

Can anyone explain rowspan and colspan, col and colgroup? And are these W3C valid and semantically correct? Under which circumstances are these useful?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明媚如初 2024-08-31 13:23:26

colspan

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

rowspan

<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 链接将提供更多信息...)。

col/colgroup

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

<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>

您还可以对列进行分组,假设第一列和第二列应该得到一个 with< /code> 为 80,第三个应该得到 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>

colspan

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

rowspan

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

w3c

as you see, this is for connecting table-cells - and because this is sometimes neccessary, it's valid (RegDwights links will give more information...).

col/colgroup

colgroup and col are used to set attributes to every line in the table (so you don't have to write width="80" for the first td in every line(tr)):

<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>

you can also group the cols, lets say the first and second column should get a with of 80, the third should get 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>
深海夜未眠 2024-08-31 13:23:26

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

Yes, they are all recommended by W3C. Here are direct links to the documentation:

请止步禁区 2024-08-31 13:23:26

rowspan 和 colspan 是允许设计者“合并”单元格的属性 - 非常类似于 Excel 中的相同命令(例如)。

colcolgroup 允许设计者将 css 应用到垂直列,而不必将 css 应用到列中的各个单元格。如果没有这些,这个任务将会困难得多,因为 html 表是基于行的。

这四个都是有效的。

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

rowspan and colspan are attributes that allow the designer to 'merge' cells - much like the same command in Excel (for example).

col and colgroup allow the designer to apply css to a vertical column, rather than having to apply css to individual cells in a column. Without these, this task would be much more difficult as html tables are row-based.

All four of these are valid.

For future reference, try http://reference.sitepoint.com/html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文