0

I'd like to specify a width for the whole column based on TH. As you can see:

<table class="table table-hover table-bordered">
  <thead>
    <tr>
      <th style="width: 50px">TEST 50</th>
      <th style="width: 100px">TEST 100</th>
      <th style="width: 150px">TEST 150</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input class"form-control" typ="text"></td>
      <td><input class"form-control" typ="text"></td>
      <td><input class"form-control" typ="text"></td>
    </tr>
  </tbody>
</table>

https://jsfiddle.net/aq9Laaew/148760/

It always gets 100%.

How could I have a table with 3 columns with 50px, 100px and 150px width.3. I use bootstrap4.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
mskuratowski
  • 4,014
  • 15
  • 58
  • 109

1 Answers1

1

Bootstrap 4 tables are always width:100%. You can use the w-auto util class on the table to make it width:auto;

Make sure the HTML is properly structured.

<table class="table table-hover table-bordered w-auto">
      <thead>
        <tr>
          <th style="width:50px">TEST 50</th>
          <th style="width:100px">TEST 100</th>
          <th style="width:150px">TEST 150</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><input class="form-control" type="text"></td>
          <td><input class="form-control" type="text"></td>
          <td><input class="form-control" type="text"></td>
        </tr>
      </tbody>
</table>

Demo: https://www.codeply.com/go/ONEQJYeJPN


Related: bootstrap 4 table column sizing

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624