简体   繁体   English

HTML 表结构复杂

[英]HTML Table with complex structure

I am having difficulty in creating the table in the image below:我在创建下图中的表格时遇到了困难:

complex table (the image itself is not appearing, please click on the link)复杂表(图片本身没有出现,请点击链接)

I have searched on stackoverflow but the answer is given without much explanation.我在stackoverflow上进行了搜索,但给出的答案没有太多解释。 Below is the code only for the complex row, that is the row that starts with cell containing "Tuesday"下面是仅用于复杂行的代码,即以包含“星期二”的单元格开头的行

<table border="1">
  <tr>
    <td rowspan="6">Tuesday</td>
    <td rowspan="2">8:00 am</td>
    <td rowspan="2">11:00 am</td>
    <td rowspan="3">XPath</td>
  </tr>
  <tr>
    <td rowspan="2">11:00 am</td>
    <td rowspan="2">2:00 pm</td>
    <td rowspan="3">XSL Transformations</td>
  </tr>
  <tr>
    <td rowspan="2">2:00 am</td>
    <td rowspan="2">5:00 pm</td>
  </tr>
</table>

With the above code, I am using three TRs, that is expected to produce three rows but only one row is being produced.使用上面的代码,我使用了三个 TR,预计会生成三行,但只生成了一行。 The result of the above code is shown below.上述代码的结果如下所示。 I am failing to understand why the row starting with "11:00 am", that is the circled row is not on a new line.我无法理解为什么以“11:00 am”开头的行,即带圆圈的行不在新行上。

actual result (the image itself is not appearing, please click on the link)实际效果(图片本身没有出现,请点击链接)

You created the structure for 6 rows, but your markup had only 3, and the 2nd row contained both spanned cells from the 1st row and the cells defined in the 2nd row.您创建了 6 行的结构,但您的标记只有 3 行,第二行包含第一行的跨单元格和第二行中定义的单元格。 That's why the browser tried to stack them horizontally.这就是浏览器试图将它们水平堆叠的原因。

To get the desired result, you should add 3 extra rows to your table and distribute cells between them so that each cell starts in the correct row ("XSL Transformations" in the 4th row, others in the 1st, 3rd and 5th rows respectively): see 1st example below.要获得所需的结果,您应该在表格中添加 3 个额外行并在它们之间分配单元格,以便每个单元格从正确的行开始(“XSL 转换”在第 4 行,其他分别在第 1、第 3 和第 5 行) :见下面的第一个例子。

By the way, the same visual result can be achieved with only 4 rows: see the 2nd example below.顺便说一句,只需 4 行就可以实现相同的视觉效果:请参见下面的第二个示例。

 <table border="1"> <tr> <td rowspan="6">Tuesday</td> <td rowspan="2">8:00 am</td> <td rowspan="2">11:00 am</td> <td rowspan="3">XPath</td> </tr> <tr></tr><:-- needed to accomodate cells with rowspan="2" from above --> <tr> <td rowspan="2">11:00 am</td> <td rowspan="2">2:00 pm</td> </tr> <tr> <td rowspan="3">XSL Transformations</td> </tr> <tr> <td rowspan="2">2:00 am</td> <td rowspan="2">5:00 pm</td> </tr> <tr></tr><:-- needed to accomodate cells with rowspan="2" from above --> </table> <hr> <table border="1"> <tr><:-- row 1 --> <td rowspan="4">Tuesday</td><:-- spans rows 1-4 --> <td>8:00 am</td><:-- spans row 1 only --> <td>11:00 am</td><!-- spans row 1 only --> <td rowspan="2">XPath</td><!-- spans rows 1-2 --> </tr> <tr><!-- row 2 --> <td rowspan="2">11:00 am</td><!-- spans rows 2-3 --> <td rowspan="2">2:00 pm</td><!-- spans rows 2-3 --> </tr> <tr><!-- row 3 --> <td rowspan="2">XSL Transformations</td><!-- spans rows 3-4 --> </tr> <tr><!-- row 4 --> <td>2:00 am</td><!-- spans row 4 only --> <td>5:00 pm</td><!-- spans row 4 only --> </tr> </table>

You maybe just should remove rowspan from hour's to obtain a better result.您也许应该从小时中删除行跨度以获得更好的结果。

<table border="1">
  <tr>
    <td rowspan="6">Tuesday</td>
    <td>8:00 am</td>
    <td>11:00 am</td>
    <td rowspan="3">XPath</td>
  </tr>
  <tr>
    <td>11:00 am</td>
    <td>2:00 pm</td>
    <td rowspan="3">XSL Transformations</td>
  </tr>
  <tr>
    <td>2:00 am</td>
    <td>5:00 pm</td>
  </tr>
</table>

I'm not sure to understand want you want, can you post a drawing of the expected result?我不确定你想要什么,你能发布一张预期结果的图吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM