简体   繁体   中英

Html table, rowspan issue

I'm trying to build a table like this:

https://1.downloader.disk.yandex.ru/preview/9c8cf709ffa53f75f44349c9fb512249/mpfs/9_71meRPOf9sZVtYIMSzTXIIQmirBLFxpBYkuucgBrZF3zDeVP6jDh2dOMBOYp-YwgO-1B-vBTiWWeE3VvxiDA%3D%3D?uid=0&filename=tablepng&disposition=inline&hash=&limit=0&content_type=image%2Fpng&size=XXL&crop= 0

Here is my solution:

<html>
    <head>
    </head>
    <body>
        <table border="1px">
            <tr>
                <td rowspan="6"></td>
                <td rowspan="3"></td>
                <td rowspan="2"></td>
            </tr>

            <tr><td rowspan="3"></td><td rowspan="2"></td></tr>
            <tr><td rowspan="2"></td></tr>
        </table>
    </body>
</html>

It seems to be logical, but it doesn't work at any browser. Is there any way in HTML to build such table?

Try this instead:

<table style="border: 1px solid #999">
    <tr>
        <td rowspan="4">&nbsp;</td>
        <td rowspan="2">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td rowspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td rowspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
</table>

jsFiddle example

You only had 3 rows, so that was never going to work. As you defined your first cell with rowspan="6" then you need at least 6 rows.

You can layout the cells by imagining 6 rows across the diagram and then you can see which row a given cell starts. The following diagram shows the each cell in order of first encounter;

So the following code will produce that layout;

<html>
    <head>
    </head>
    <body>
        <table border="1px">
            <tr>
                <td rowspan="6">&nbsp;</td> <!-- Box 1 -->
                <td rowspan="3">&nbsp;</td> <!-- Box 2 -->
                <td rowspan="2">&nbsp;</td> <!-- Box 3 -->
            </tr>
            <tr></tr>
            <tr><td rowspan="2">&nbsp;</td></tr> <!-- Box 4 -->
            <tr><td rowspan="3">&nbsp;</td></tr> <!-- Box 5 -->
            <tr><td rowspan="2">&nbsp;</td></tr> <!-- Box 6 -->
            <tr></tr>
        </table>
    </body>
</html>

The &nbsp; s were so I could see the structure.

Hope this helps.

You can stick with 6/3/2 rowspan, but you need to include the empty rows you are spanning. For example:

<table border="1px">
    <tr>
        <th rowspan="6">6</th>
        <td rowspan="3">3</td>
        <td rowspan="2">2</td>
    </tr>
    <tr><!-- empty row --></tr>
    <tr><td rowspan="2">2</td></tr>
    <tr><td rowspan="3">3</td></tr>
    <tr><td rowspan="2">2</td></tr>
    <tr><!-- empty row --></tr>
</table>

Fiddle riddle diddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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