多列和多行在Bootstrap表格中

huangapple go评论73阅读模式
英文:

Multiple Columns and Rows in Bootstrap Table

问题

我正在寻求在Bootstrap 5中实现类似这样的表格。

我已经尝试了以下代码,但结果很奇怪,如下图所示。

我不知道我漏掉了什么,已经搜索了很多,但没有找到合适的解决方案。如果这里有人可以帮我解决这个问题,请告诉我。

谢谢!

英文:

I am looking to achieve table something like this in bootstrap 5.

多列和多行在Bootstrap表格中

I have tried like this

<table class="table table-bordered">
    <thead>
        <tr>
            <th><span>Domain</span></th>
            <th colspan="3"><span>DATE</span></th>
            <th colspan="3"><span>DATE</span></th>
            <th colspan="3"><span>DATE</span></th>
            <th colspan="3"><span>DATE</span></th>
            <th colspan="3"><span>DATE</span></th>
            <th colspan="3"><span>DATE</span></th>
            <th colspan="3"><span>DATE</span></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><span>Example1</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >            
        </tr>
        <tr>
            <td><span>Example2</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
            <td  rowspan="3" ><span>DR</span></td >
            <td  rowspan="3" ><span>IR</span></td >
            <td  rowspan="3" ><span>SR</span></td >
        </tr>
    </tbody>
</table>

But I am getting weird result like this image

多列和多行在Bootstrap表格中

I am not getting idea what I am missing, searched lot but not found any proper solution for the same. Let me know if anyone here can help me for solve the issue.

Thanks!

答案1

得分: 2

你在DOMAIN上缺少rowspan,以及标题部分缺少第二个tr
此外,后续的td不应该有colspan

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th rowspan="2" class="align-middle"><span>Domain</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                    <th><span>DR</span></th>
                    <th><span>IR</span></th>
                    <th><span>SR</span></th>
                </tr>
            </thead>
            <tbody> 
                <tr>
                    <td><span>Example1</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                </tr>
                <tr>
                    <td><span>Example2</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                    <td><span>DR</span></td>
                    <td><span>IR</span></td>
                    <td><span>SR</span></td>
                </tr>
            </tbody>
        </table>

<!-- end snippet -->
英文:

You are missing the rowspan on the DOMAIN, and a second tr in the header.
Also you shouldn't have colspans for the subsequent tds:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;/&gt;
&lt;table class=&quot;table table-bordered&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th rowspan=&quot;2&quot; class=&quot;align-middle&quot;&gt;&lt;span&gt;Domain&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;th colspan=&quot;3&quot; class=&quot;text-center&quot;&gt;&lt;span&gt;DATE&lt;/span&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt; 
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;Example1&lt;/span&gt;&lt;/td &gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span&gt;Example2&lt;/span&gt;&lt;/td &gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;DR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;IR&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;SR&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年4月1日 00:20:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定