【问题标题】:Please explain rowspan and colspan, col and colgroup请解释rowspan和colspan,col和colgroup
【发布时间】:2015-01-31 23:34:24
【问题描述】:

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

【问题讨论】:

    标签: css xhtml semantic-markup


    【解决方案1】:

    colspan

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

    col/colgroup

    colgroupcol 用于为表中的每一行设置属性(因此您不必为每一行中的第一个tdwidth="80"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>
    

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

    【讨论】:

    • 添加了 col/colgroup,希望对您有所帮助。
    • 我们可以使用 width="80" 吗?是不是已经弃用了
    • 如果我没记错的话,只有 td、th、pre 和...其他东西不推荐使用宽度 - 但如果你不想使用它,你可以通过使用样式表来获得相同的效果.
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      这四个都是有效的。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-16
        • 2017-06-06
        • 2023-03-17
        • 2018-07-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-13
        • 2014-07-22
        相关资源
        最近更新 更多