Html代碼中table跨2行和跨2列的用法

來源:互聯網
上載者:User
一直以來總是會寫跨2列的Html代碼,不會寫跨2行的例子,找機會研究了一下!
先說說跨2列的例子,這個很好理解

例1  跨2列:1<table border="1">
2                <tr>
3                    <td colspan="2" align="center">111</td>
4                </tr>
5                <tr>
6                    <td>222</td>
7                    <td>333</td>
8                </tr>
9  </table>

顯示效果如下:

111
222 333

Html代碼總是一行一行讀的,先讀第1行,碰到了colspan=2 那麼就預先佔用2列的位置
然後第2行讀時就先讀第一列,再讀第2列

例2  右跨2行:

1<table border="1">
2                <tr>
3                    <td>111</td>
4                    <td rowspan="2">222</td>
5                </tr>
6                <tr>
7                    <td>333</td>
8                </tr>
9            </table>

顯示效果如下:

111 222
333

Html代碼先讀第1行第1列,然後讀到第2列時遇到rowspan=2 ,那麼預留2行的位置
然後再讀第2行第1列。

例3  左跨2行:

1<table border="1">
2                <tr>
3                    <td rowspan="2">111</td>
4                    <td>222</td>
5                </tr>
6                <tr>
7                    <td>333</td>
8                </tr>
9            </table>

顯示效果如下:

111 222
333

例4  跨2行和跨2列結合:

 1<table border="1">
 2                <tr>
 3                    <td rowspan="2">111</td>
 4                    <td>222</td>
 5                    <td>333</td>
 6                </tr>
 7                <tr>
 8                    <td>444</td>
 9                    <td>555</td>
10                </tr>
11                <tr>
12                    <td>666</td>
13                    <td colspan="2">777</td>
14                </tr>
15            </table>
111 222 333
444 555
666 777

開始先讀第1行第1列,預留2行,讀出第1行的2,3列,
然後讀第2行的1,2列,然後讀第3行的第一列,後來
再讀第2列橫跨2列。

不知道我這樣的理解是否正確,有更好的理解方法的請不吝賜教!謝謝!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.