简体   繁体   English

HTML中有2列的表格; 第一列是7行,第二列是1行

[英]Table in HTML with 2 columns; first column is 7 rows, second column is 1 row

I'm trying to create a table in HTML. 我正在尝试用HTML创建一个表。 7 rows in the first column, only 1 in the second. 第一列中有7行,第二列中只有1行。 I can't figure it out. 我不知道。 I feel like I am missing something simple. 我觉得我缺少一些简单的东西。

You want to use the rowspan attribute to stretch the second column over the rows of the first column, as shown below. 您要使用rowspan属性将第二列延伸到第一列的行上,如下所示。

Reference: http://www.w3.org/TR/html401/struct/tables.html#h-11.2.6.1 参考: http : //www.w3.org/TR/html401/struct/tables.html#h-11.2.6.1

 td { border: 1px solid gray; } 
 <table> <tr> <td>C 1</td> <td rowspan="7">C 2</td> </tr> <tr> <td>C 1</td> </tr> <tr> <td>C 1</td> </tr> <tr> <td>C 1</td> </tr> <tr> <td>C 1</td> </tr> <tr> <td>C 1</td> </tr> <tr> <td>C 1</td> </tr> </table> 

You can simply put a second td element in the first row, and change its rowspan to 7 您只需将第二个td元素放在第一行,并将其rowspan更改为7

 <table border="1" style="width:100%"> <tr> <td>a</td> <td rowspan="7">b</td> </tr> <tr> <td>a</td> </tr> <tr> <td>a</td> </tr> <tr> <td>a</td> </tr> <tr> <td>a</td> </tr> <tr> <td>a</td> </tr> <tr> <td>a</td> </tr> </table> 

You can use the rowspan attribute to have a cell span multiple rows. 您可以使用rowspan属性使一个单元格跨越多行。

Code: 码:

<html>
    <body>
        <table>
            <tr>
                <td>Row 1</td>
                <td rowspan="7">Row 1</td>
            </tr>
            <tr>
                <td>Row 2</td>
            </tr>
            <tr>
                <td>Row 3</td>
            </tr>
            <tr>
                <td>Row 4</td>
            </tr>
            <tr>
                <td>Row 5</td>
            </tr>
            <tr>
                <td>Row 6</td>
            </tr>
            <tr>
                <td>Row 7</td>
            </tr>
        </table>
    </body>
</html>

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

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