Updated 2018
Make sure your table includes the table
class. This is because Bootstrap 4 tables are "opt-in" so the table
class must be intentionally added to the table.
http://codeply.com/go/zJLXypKZxL
Bootstrap 3.x also had some CSS to reset the table cells so that they don't float..
table td[class*=col-], table th[class*=col-] {
position: static;
display: table-cell;
float: none;
}
I don't know why this isn't is Bootstrap 4 alpha, but it may be added back in the final release. Adding this CSS will help all columns to use the widths set in the thead
..
UPDATE (as of Bootstrap 4.0.0)
Now that Bootstrap 4 is flexbox, the table cells will not assume the correct width when adding col-*
. A workaround is to use the d-inline-block
class on the table cells to prevent the default display:flex of columns.
Another option in BS4 is to use the sizing utils classes for width...
<thead>
<tr>
<th class="w-25">25</th>
<th class="w-50">50</th>
<th class="w-25">25</th>
</tr>
</thead>
Lastly, you could use d-flex
on the table rows (tr), and the col-*
grid classes on the columns (th,td)...
<table class="table table-bordered">
<thead>
<tr class="d-flex">
<th class="col-3">25%</th>
<th class="col-3">25%</th>
<th class="col-6">50%</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-sm-3">..</td>
<td class="col-sm-3">..</td>
<td class="col-sm-6">..</td>
</tr>
</tbody>
</table>
Note: Changing the TR to display:flex can alter the borders