I have a static PHP site I'm using Bootstrap on. The tables are controlled by Bootstrap.
I've noticed that I have seemingly no control over the lengths of the TD
sections so that I can prevent the phone numbers, etc..., from wrapping. As you can see there is plenty of space on the end, just don't know how to spread that space out.
I tried inline widths on the <th>
but nothing happens:
<table class="table table-condensed table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th width="12%">Last Name</th>
<th width="12%">First Name</th>
<th width="12%">Spouse's Name</th>
<th width="20%">Address</th>
<th width="5%">City</th>
<th width="12%"class="did_phone">Phone</th>
<th width="15%">E-Mail</th>
<th width="15%"></th>
</tr>
</thead>
<tbody>
So... how does one change the <td>
widths, make adjustments so there is no wrapping, in Bootstrap?
Change column width To change the width to a specific measurement, click a cell in the column that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Column Width box, and then specify the options you want.
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. 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.
Small table: To make the table smaller in size use the class table-sm along with the class table within the <table> tag. This reduces the cell padding to half. To make the dark table smaller in size use the combination of classes table, table-sm, and table-dark within the <table> tag.
The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content.
Bootstrap makes tables 100%
. So Tables th
is set to 100%
. The solution is to make it auto
. So I simply overrode Bootstrap by adding the following to my css:
table th {
width: auto !important;
}
And everything lined up perfectly.
You could try using this style="width:12%" in each th.
Example:
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th style="width:12%">Last Name</th>
<th style="width:12%">First Name</th>
<th style="width:12%">Spouse's Name</th>
<th style="width:20%">Address</th>
<th style="width:5%">City</th>
<th style="width:12%"class="did_phone">Phone</th>
<th style="width:15%">E-Mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Last Name</td>
<td>First Name</td>
<td>Spouse's Name</td>
<td>Adress</td>
<td>City</td>
<td>Phone</td>
<td>E-Mail</td>
</tr>
</tbody>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With