英文:
Multiple Columns and Rows in Bootstrap Table
问题
我正在寻求在Bootstrap 5中实现类似这样的表格。
我已经尝试了以下代码,但结果很奇怪,如下图所示。
我不知道我漏掉了什么,已经搜索了很多,但没有找到合适的解决方案。如果这里有人可以帮我解决这个问题,请告诉我。
谢谢!
英文:
I am looking to achieve table something like this in bootstrap 5.
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
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 colspan
s for the subsequent td
s:
<!-- 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 colspan="3" class="text-center"><span>DATE</span></th>
<th colspan="3" class="text-center"><span>DATE</span></th>
<th colspan="3" class="text-center"><span>DATE</span></th>
<th colspan="3" class="text-center"><span>DATE</span></th>
<th colspan="3" class="text-center"><span>DATE</span></th>
<th colspan="3" class="text-center"><span>DATE</span></th>
<th colspan="3" class="text-center"><span>DATE</span></th>
</tr>
<tr>
<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 -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论