【问题标题】:Bootstrap fixed width table columns in container fluid容器流体中的引导固定宽度表列
【发布时间】:2020-09-10 04:12:58
【问题描述】:

我有一个问题要问你。我正在尝试在 container fluid div 中修复表格列的大小。我尝试设置 style="width: xx.x%" 但它会根据单元格内容继续更改。

我也尝试过使用 max-with,但它仍然不起作用。在我的代码下面:

    <div class="container-fluid">
          <div class="row">
            <div class="col-12">
                  <table class="table table-sm text-nowrap">
            <thead>
              <tr class="bg-info text-white">
                <th style="max-width: 1%">2020</th>
                <th style="max-width: 9%">Voci</th>
                <th class="text-center" style="max-width: 7.5%">Gen</th>
                <th class="text-center" style="max-width: 7.5%">Feb</th>
.......

我希望该列具有固定宽度(广告示例最大值和最小值等于 7.5%)。 我怎么能在引导程序中得到这个?

【问题讨论】:

    标签: html django html-table bootstrap-4 django-templates


    【解决方案1】:

    您应该为您的table 使用d-flex 属性以生成fix width

    您可以使用col 类来指定每列的宽度。

    <!doctype html>
    <html lang="en">
    
    <head>
      <!-- Required meta tags -->
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
      <!-- Bootstrap CSS -->
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
        integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    </head>
    
    <body>
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <table id="productSizes" class="table">
              <thead>
                <tr class="bg-info d-flex">
                  <th class="col-3">2020</th>
                  <th class="col-3">Voice</th>
                  <th class="col-3">Gen</th>
                  <th class="col-3">Feb</th>
                </tr>
              </thead>
              <tbody>
                <tr class="d-flex">
                  <td class="col-3">First Column with fixed width look at that, it is moving text to next line if it
                    overflowing</td>
                  <td class="col-3">Second Column with fixed width</td>
                  <td class="col-3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita, atque earum
                    asperiores ex
                    quod quia mollitia dese</td>
                  <td class="col-3">This is third clumn</td>
                </tr>
                <tr class="d-flex">
                  <td class="col-3">8</td>
                  <td class="col-3">84 - 86</td>
                  <td class="col-3">66 - 68</td>
                  <td class="col-3">94 - 96</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    
    </body>
    
    </html>

    【讨论】:

    • 对我不起作用。因为我有超过 12 列,并且 col-3 溢出了网格
    • 那么你必须提供你正在处理的完整代码。
    猜你喜欢
    • 2014-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多