html - 在双头表的 Bootstrap 中居中 <th>

标签 html css bootstrap-4

你好,我有一张 table ,我想把一个放在另外两个中间。 我想将 Vieillesse de base 的位置更改为显示在 ProvisionnelRé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"

JS FIDDLE DEMO

<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/

相关文章:

javascript - 使用 JavaScript 显示多个 CSS 弹出窗口

html - Bootstrap 4 : How to horizontally align elements inside a drop-down?

html - 如何让文本区域占据 div 中的剩余高度?

html - slider 无法正常工作

javascript - Bootstrap Datetimepicker 跨度中断

javascript - 如何将一个元素与其正下方的另一个元素水平对齐?

javascript - 未捕获的类型错误 : Cannot read property 'setAttribute' of undefined at Object. onLoad

html - 在基于 Bootstrap 的网站中更改方向后字体大小发生变化

Javascript 或 Jquery - 将输入字段限制为仅 8 位小数

javascript - 如何同时控制两个滚动条