简体   繁体   中英

HTML table using rowspan and colspan

I'm trying to create a HTML table like in this image;

实现附在 html 中的表格

I tried the following but it did not work.

 <table border="1"> <tr> <th rowspan="2" colspan="2">1,1</th> <td>1,1</td> </tr> <tr> <td>1,1</td> </tr> <tr> <td>1,1</td> <td colspan="2">1,1</td> </tr> </table>

You can try this:

 table { border-collapse: collapse; } td { text-align: center; border: 1px solid; }
 <table> <col width=100><col width=100><col width=100> <tr> <td colspan="2" style="border-bottom: none;">1,1</td> <td>1,3</td> </tr> <tr> <td colspan="2" style="border-top: none;"></td> <td>2,3</td> </tr> <tr> <td>3,1</td> <td colspan="2">3,2</td> </tr> </table>

hi your code is good just add with to see the difference

 <table border="1"> <tr> <th rowspan="2" colspan="2" style="width: 95px;">1,1</th> <td>1,1</td> </tr> <tr> <td>1,1</td> </tr> <tr> <td style="width: 20px;">1,1</td> <td colspan="2">1,1</td> </tr> </table>

This is how you could build the table in your picture by using rowspan and colspan :

 table { width: 100%; border-collapse: collapse; } td { border: 1px solid black; text-align: center; width: 33%; }
 <table> <tr> <td colspan="2" rowspan="2">1,1</td> <td>1,3</td> </tr> <tr> <td>2,3</td> </tr> <tr> <td>3,1</td> <td colspan="2">3,2</td> </tr> </table>

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