简体   繁体   English

在HTML表的同一单元格中使用colspan和rowspan

[英]Using colspan and rowspan in same cell in HTML table

My default table looks like this, with 4 separate cells: 我的默认表如下所示,具有4个单独的单元格:

看这张图片

I want to create a table with this schema (merge r1c1 & r1c2 &r2c2): 我想用这种模式创建一个表(合并r1c1&r1c2&r2c2):

看这张图片

My default table code is: 我的默认表代码是:

<table border="2">
<caption style="border: 1px dotted;">Table 1</caption>
<tr>
<td>r1c1</td>
<td>r1c2</td>
</tr>
<tr>
<td>r2c1</td>
<td>r2c2</td>
</tr>
</table>

And my merged table code look like this (but doesn't do what I wanted!): 我的合并表代码看起来像这样(但不执行我想要的!):

<table border="2">
<caption style="border: 1px dotted;">Table 1</caption>
<tr>
<td colspan="2" rowspan="2">r1c1 & r1c2 & r2c2</td>
</tr>
<tr>
<td >r2c1</td>
</tr>
</table>

How do I get those three cells merged using colspan and rowspan? 如何使用colspan和rowspan合并这三个单元格?

No you cannot implement this with table cells. 不,您不能使用表单元格来实现这一点。 However, A similar layout can be displayed using css styles as shown in this fiddle . 但是,可以使用css样式显示类似的布局,如该小提琴所示。

html HTML

<table border="2">
    <caption style="border: 1px dotted;">Table 1</caption>
    <tr>
        <td id="r1c1" colspan="2">r1c1 & r1c2</td>
    </tr>
    <tr>
        <td>r2c1</td>
        <td id="r2c2" rowspan="2">r2c2</td>
    </tr>
</table>

css CSS

#r1c1 {
border: none !important;
}

#r2c2 {
border: none !important;
}


You can create a similar L shape using div tags by applying similar css styles as shown in this fiddle . 您可以使用div标签创建类似的L形,方法是使用此小提琴中所示的类似CSS样式。 Also you can refer this link to find css styles for creating various shapes. 您也可以参考此链接找到用于创建各种形状的css样式。

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

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