【问题标题】:A table row was 2 columns wide, which is less than the column count established by the first row (3)表格行宽 2 列,小于第一行建立的列数 (3)
【发布时间】:2016-05-01 04:09:07
【问题描述】:

我使用https://validator.w3.org/nu/#file 来更正我的 html 课程,但我不断收到此错误

警告:表格行宽 2 列,小于第一行 (3) 建立的列数。 从第 31 行第 31 列开始;到第 32 行第 6 列 环↩↩

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Assignment 3B</title>
<style>
table, th, td {
    border: 1px solid black;
    background-color: #FFFFCC;
}
th, td {
    width: 25%;
}
th {
    height: 50px
}
th, td {
    padding: 10px;
}
</style>
</head>
<body>

<table>

    <tr>
    <th colspan="3"> Seasons </th> 
    </tr> 
    <tr> 
    <td rowspan="3"> March/April </td>
    <th rowspan="4"> Spring </th> 
    </tr>

    <tr>
    <td > <b> Cold </b></td> 
    </tr>
    <tr> 
    <td> Warm </td> 
    </tr> 
    <tr> 
    <th rowspan="1">
    <img src="tree1.png" alt="tree" style="width:150px;height:150px;"> 
    </th>
    <td style="background-image: url(Light_Pink_430051_i0.png)"> <b>Warm </b> </td>
    </tr>

    </table> 
</body>
</html>

请帮帮我

【问题讨论】:

  • 请张贴图片的外观,因为您的代码在匹配列和行时存在结构错误
  • 请检查:developer.mozilla.org/en/docs/Web/HTML/Element/… 导致&lt;th&gt; 只能在第一个&lt;tr&gt;&lt;thead&gt;&lt;tr&gt;
  • 在看到您希望它看起来像什么的评论后,感觉使用带宽度和浮动的 div 会更好。
  • 哦。这是给学校的,你需要用桌子吗?

标签: html


【解决方案1】:

您的第 1 行有 3 列,第 2 和第 5 行有 2 列,第 3 和第 4 行有 1 列

试试这个 html:

table,
th,
td {
  border: 1px solid black;
  background-color: #FFFFCC;
}
th,
td {
  width: 25%;
}
th {
  height: 50px
}
th,
td {
  padding: 10px;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>Assignment 3B</title>
</head>

<body>
  <table>
    <tr>
      <!-- 2 columns only -->
      <th colspan="2">Seasons</th>
    </tr>
    <tr>
      <th>March/April</th>
      <th>Spring</th>
    </tr>
    <tr>
      <td> <b> Cold </b>
      </td>
      <td>Warm</td>
    </tr>
    <tr>
      <th>
        <img src="tree1.png" alt="tree" style="width:150px;height:150px;">
      </th>
      <td style="background-image: url(Light_Pink_430051_i0.png)"> <b>Warm </b> 
      </td>
    </tr>
  </table>
</body>

</html>

【讨论】:

    【解决方案2】:

    出现此行为是因为您选择的 tdth 包含的列没有 rowspan 中定义的列那么多。

    【讨论】:

      【解决方案3】:

      我不想为你回答你的学校问题,但我会尽力帮助你解决问题

      所以请记住,行是交叉的,列是上下的。当你定义一个表时,你定义了这个表。然后是表格中的行和每一行中的每一列。

      所以拿那张图片并尝试首先考虑行

      第一个单元格是对的。它跨越 3 列

      然后在下一行。第一个单元格跨越 2 行,第二个单元格跨越 3 行,第三个单元格跨越一个行

      在下一行中,您已经处理了第一个和第二个列,需要定义第三个单元格

      在最后一行你需要定义第一个单元格,第二个单元格已经在第二行处理了。然后你需要定义最后一个单元格

      希望你能从那里拿走它

      【讨论】:

        猜你喜欢
        • 2016-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-15
        • 2021-12-08
        • 1970-01-01
        • 1970-01-01
        • 2014-10-25
        相关资源
        最近更新 更多