怎样合并html中的单元格

html-css011

怎样合并html中的单元格,第1张

在Html合并单元格时,使用的属性为: 跨行合并:rowspan, 跨列合并: colspan.

第一部分:rowspan使用方法

<table border=2 width="50%">

<tr>

<td rowspan=2>行1,条目1 </td>

<td>行1,条目2</td>

</tr>

<tr><td>行2,条目1</td></tr>

</table>

1. 没有增加rowspan时的效果是:

行1,条目1行1,条目2

行2,条目1

2. 增加rowspan后的效果是:

行1,条目1行1,条目2

行2,条目1

第二部分:colspan使用方法

<table border=2 width="50%">

<tr>

<td>行1,条目1 </td>

<td>行1,条目2</td>

</tr>

<tr><td colspan=2 align="center">行2,条目1</td></tr>

</table>

1. 没有增加rowspan时的效果是:

行1,条目1行1,条目2

行2,条目1"没有内容"

2. 增加rowspan后的效果是:

行1,条目1行1,条目2

行2,条目1(整个为一个单元格)

colspan 是合并列,rowspan是合并行,合并行的时候,比如rowspan="2",它的下一行tr会少一列;合并列的时候 colspan="2",此行的列会少一列。

代码演示:

<table border="1" style={{margin:200}}>

   

<tbody>

     

<tr>

       

<th colspan="2">我是占位符</th>

     

<th colspan="2">我是占位符</th>

     

</tr>

     

<tr>

       

<th rowspan="2">我是占位符</th>

       

<th>我是占位符</th>

       

<th>我是占位符</th>

       

<th>我是占位符</th>

     

</tr>

     

<tr>

       

<th>我是占位符</th>

       

<th>我是占位符</th>

<th>我是占位符</th>

     

</tr>

   

</tbody>

 

</table>

演示结果

扩展资料:

rowspan规定表头单元格应该横跨的行数。注意: rowspan="0" 告知浏览器使单元格横跨到表格组件中的最后一个行(thead、tbody 或 tfoot)。

colspan属性可以实现水平单元格合并。

例如:

<table border="1">

<tr>

 <th>Month</th>

 <th>Savings</th>

</tr>

<tr>

 <td colspan="2">January</td>

</tr>

<tr>

 <td colspan="2">February</td>

</tr>

</table>

扩展资料:

注意事项

一、语法

<td colspan="value">

二、HTML 表格有两类单元格:

1、表头单元

包含头部信息(由 th 元素创建)

2、标准单元

包含数据(由 td 元素创建)

td 元素中的文本一般显示为正常字体且左对齐。

三、colspan和rowspan这两个属性用于创建特殊的表格。

1、colspan用来指定单元格横向跨越的列数

colspan就是合并列的,colspan=2的话就是合并两列。

2、rowspan用来指定单元格纵向跨越的行数

rowspan就是用来合并行的。

比如:rowspan=2就是合并两行,rowspan通常使用在td和th标签中。

row:行,span:跨度,跨距,范围

col:列,span:跨度,跨距,范围