你好,我有一张 table ,我想把一个放在另外两个中间。 我想将 Vieillesse de base 的位置更改为显示在 Provisionnel 和 Régularisation 的中心。
这是我的 HTML:
<div class="row mt-1">
<div class="col-12">
<table class="table table-striped table-adjust ">
<thead class="cordonnes-cabinet">
<tr>
<th scope="col">Date</th>
<th scope="col" style="text-align:center" colspan="2">Vieillesse de base</th>
<th scope="col" style="text-align:right">Complémentaire</th>
<th scope="col" style="text-align:right">Total</th>
</tr>
<tr>
<th scope="col">...</th>
<th scope="col" style="text-align:right">Provisionnel</th>
<th scope="col" style="text-align:right">Régularisation</th>
<th scope="col" style="text-align:right">...</th>
<th scope="col" style="text-align:right">...</th>
</tr>
</thead>
<tbody class="cordonnes-cabinet">
@for (int i = 0; i < echeancierGeneriqueAjustee.Count; i++)
{
<tr>
<th style="font-weight:100">@(echeancierGeneriqueAjustee[i]["Date"])</th>
<td style="text-align:right">@(echeancierGeneriqueAjustee[i]["MontantProv"])</td>
<td style="text-align:right">@(echeancierGeneriqueAjustee[i]["MontantRegul"])</td>
<td style="text-align:right">@(echeancierGeneriqueAjustee[i]["MontantComplement"])</td>
<td style="text-align:right">@(echeancierGeneriqueAjustee[i]["TotalEcheance"])</td>
</tr>
}
<tr>
<th style="font-size:14px">Total</th>
<td style="text-align:right">@(echeancierGeneriqueAjustee[0]["TotalProv"])</td>
<td style="text-align:right">@(echeancierGeneriqueAjustee[0]["TotalRegul"])</td>
<td style="text-align:right">@(echeancierGeneriqueAjustee[0]["TotalComplement"])</td>
<td style="text-align:right">@(echeancierGeneriqueAjustee[0]["Total"])</td>
</tr>
</tbody>
</table>
</div>
</div>
最佳答案
这样做的关键是在 th
中使用 html colspan
,模拟与第二行的宽度相等。那么你只需要使用.text-center
。
在你的特殊情况下,在第二个 th
colspan="2"
<table class="table">
<thead class="cordonnes-cabinet">
<tr>
<th>Date</th>
<th colspan="2" class="text-center">Vieillesse de base</th>
<th>Complémentaire</th>
<th>Total</th>
</tr>
<tr>
<th style="width:10%">...</th>
<th class="text-center">Provisionnel</th>
<th class="text-center">Régularisation</th>
<th>...</th>
<th>...</th>
</tr>
</thead>
<tbbody>
<tr>
<th>col1</th>
<td class="text-center">col2</td>
<td class="text-center">col3</td>
<td>col4</td>
<td>col5</td>
</tr>
</tbbody>
</table>
关于html - 在双头表的 Bootstrap 中居中 <th>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53433761/