Bootstrap 4 table with one column larger than others
I found a solution that works for my case, in Set min-width in HTML table's <td>:
<td style="min-width:100px">
Table column sizing
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
..
Bootstrap 4 Alpha 2 Demo
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>
Bootstrap 4 Alpha 6 Demo
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>
Bootstrap 4.0.0 (stable) Demo
Note: Changing the TR to display:flex can alter the borders
Making a Bootstrap table column fit to content
Make a class that will fit table cell width to content
.table td.fit,
.table th.fit {
white-space: nowrap;
width: 1%;
}
Table wider than Bootstrap column container
Try adding word-wrap
and word-break
td {
word-wrap:break-word;
word-break:break-all;
}
Here's your updated Bootply
How to set up fixed width for td?
For Bootstrap 4.0:
In Bootstrap 4.0.0 you cannot use the col-*
classes reliably (works in Firefox, but not in Chrome).
You need to use OhadR's answer:
<tr>
<th style="width: 16.66%">Col 1</th>
<th style="width: 25%">Col 2</th>
<th style="width: 50%">Col 4</th>
<th style="width: 8.33%">Col 5</th>
</tr>
For Bootstrap 3.0:
With twitter bootstrap 3 use: class="col-md-*"
where * is a number of columns of width.
<tr class="something">
<td class="col-md-2">A</td>
<td class="col-md-3">B</td>
<td class="col-md-6">C</td>
<td class="col-md-1">D</td>
</tr>
For Bootstrap 2.0:
With twitter bootstrap 2 use: class="span*"
where * is a number of columns of width.
<tr class="something">
<td class="span2">A</td>
<td class="span3">B</td>
<td class="span6">C</td>
<td class="span1">D</td>
</tr>
** If you have <th>
elements set the width there and not on the <td>
elements.
How to set the size of a column in a Bootstrap responsive table
Bootstrap 4.0
Be aware of all migration changes from Bootstrap 3 to 4. On the table you now need to enable flex box by adding the class d-flex
, and drop the xs
to allow bootstrap to automatically detect the viewport.
<div class="container-fluid">
<table id="productSizes" class="table">
<thead>
<tr class="d-flex">
<th class="col-1">Size</th>
<th class="col-3">Bust</th>
<th class="col-3">Waist</th>
<th class="col-5">Hips</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-1">6</td>
<td class="col-3">79 - 81</td>
<td class="col-3">61 - 63</td>
<td class="col-5">89 - 91</td>
</tr>
<tr class="d-flex">
<td class="col-1">8</td>
<td class="col-3">84 - 86</td>
<td class="col-3">66 - 68</td>
<td class="col-5">94 - 96</td>
</tr>
</tbody>
</table>
bootply
Bootstrap 3.2
Table column width use the same layout as grids do; using col-[viewport]-[size]
. Remember the column sizes should total 12; 1 + 3 + 3 + 5 = 12
in this example.
<thead>
<tr>
<th class="col-xs-1">Size</th>
<th class="col-xs-3">Bust</th>
<th class="col-xs-3">Waist</th>
<th class="col-xs-5">Hips</th>
</tr>
</thead>
Remember to set the <th>
elements rather than the <td>
elements so it sets the whole column. Here is a working BOOTPLY.
Thanks to @Dan for reminding me to always work mobile view (col-xs-*
) first.
Table columns not of equal size in Bootstrap 4
Try to remove class="col-4" from the code.
Bootstrap 4 equal column widths with responsive table
Actually, I solved this one. All I had to do was:
.table-product [class^="col-"] {
flex-shrink: 1;
}
Bootstrap 4 Table How to make column widths even?
You can see the width is the minimum of the tableheaders. Some columns are smaller because the tablehead ist just a few letters.
As a solution you can set the width of th
so every have the same width. You can do this either relative or with a fixed width
th, td{
width: 7.7% /* relative: 100%:13 columns= 7.6923076923 per column */
width: 50px /* fixed */
}
There are only bootstrap-classes for width:25%, 50%, 75% and 100%, so you have to set up the rule in css. Your table also should be wide enough so it display content correctly.
How can i make each column equal to each other in bootstrap 4
You need to differentiate somehow your data columns from your command columns and apply your CSS just for your data columns:
td.table:not(.command) {
border: 1px solid black;
width: 15% !important;
}
<table class="table table-bordered table-responsive-sm table-hover">
<thead>
<tr>
<th>Date</th>
<th>TimeSlot</th>
<th>Room</th>
<th>Attendees</th>
<th>update</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<tr class="table">
<td class="table">Date</td>
<td class="table">Time</td>
<td class="table">Room</td>
<td class="table">invitee</td>
<td class="table" style="display: none">reservationid</td>
<td class="table" style="display: none">invitedby</td>
<td class="table" style="display: none">workspace</td>
<td class="table command">
<a onclick="onUpdate()" style="color: #007bff; cursor: pointer"> <i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
</td>
<td class="table command">
<a onclick="onDelete()" style="color: #007bff; cursor: pointer"> <i class="fa fa-trash" aria-hidden="true"></i></a> </td>
</tr>
</tbody>
}
</table>
Related Topics
Swap Div Position With CSS Only
Browsers Scrollbar Is Under My Fixed Div
Is Float For Layout Bad? What Should Be Used in Its Place
How Are the Points in CSS Specificity Calculated
Remove White Space Below Image
How to Select the "Last Child" With a Specific Class Name in Css
How to Float 3 Divs Side by Side Using Css
How to Add Border in My Clip-Path: Polygon(); CSS Style
Changing Background Image With Css3 Animations
How to Disable the Border on Bootstrap 4 Cards
Why It Is Not Taking 100% Height in Material Design
Size of Html5 Canvas Via CSS Versus Element Attributes
What Are the Differences Between Flex-Basis and Width
How to Make Background-Size Work in Ie
::Slotted CSS Selector For Nested Children in Shadowdom Slot