Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase column width for Bootstrap 4 table

I need to increase column width, i tried width-%,PX,rem but that's not working. I can able to increase the column width if the table have small number of columns but in my scenario if i have more than 15 columns i cant change the width.

<div class="table-responsive">
<table class="table">
  <thead>
    <tr>

<th scope="col">#</th><th scope="col">#</th>

      <th scope="col" style="width: 500px;">Heading heading'</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>

      <th scope="col">Heading</th><th scope="col">Heading</th>
    </tr>
  </thead>
  <tbody>
    <tr>

 <th scope="row">1</th><th scope="row">1</th>

      <td style="width: 300px;">jksdfn jhs fjidsh fj id hidsfdsfd</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>
    </tr>
   <tr>

 <th scope="row">1</th><th scope="row">1</th>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>

      <td>Cell</td><td>Cell</td>
    </tr>
  </tbody>
</table>

I need to increase the third column in the table below, attached image for referene. enter image description here I've used Always Responsive Bootstrap 4 Table

like image 341
ganesh Avatar asked Feb 13 '18 10:02

ganesh


People also ask

How do I change the width of a column in bootstrap table?

You can simply add the w-auto class into the table element to place an auto width to that table column. The width of those columns will automatically adapt to the content of that column. Which implies that it will perpetually take up the minimum width needed to display its content.

How do you resize column width in a table?

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.

How do you set the size of a column in a bootstrap responsive table?

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.

What are the two ways to resize a column width?

To change the width of columns to fit the contents, select the column or columns that you want to change, and then double-click the boundary to the right of a selected column heading. To change the width of all columns on the worksheet, click the Select All button, and then drag the boundary of any column heading.


1 Answers

You need to use min-width instead of width.

Click the "run code snippet" button below and expand to full page:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<table class="table table-responsive">
    <thead>
        <tr>

            <th scope="col">#</th>
            <th scope="col">#</th>

            <th scope="col" style="width: 500px;">Heading heading'</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>

            <th scope="col">Heading</th>
            <th scope="col">Heading</th>
        </tr>
    </thead>
    <tbody>
        <tr>

            <th scope="row">1</th>
            <th scope="row">1</th>

            <td style="min-width: 300px;">jksdfn jhs fjidsh fj id hidsfdsfd</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>
        </tr>
        <tr>

            <th scope="row">1</th>
            <th scope="row">1</th>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>

            <td>Cell</td>
            <td>Cell</td>
        </tr>
    </tbody>
</table>
like image 92
WebDevBooster Avatar answered Oct 01 '22 08:10

WebDevBooster