Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap table in div horizontal scroll not work

In the content, I put a div with a table inside. I need it to scroll horizontally. I've spent hours researching and trying some solutions.

<div style="width:100%; overflow: scroll;">
    <table style="width:2000px;">
            <tr>
                <td>very large width table with scroll horizontal</td>
                <td>x</td>
                <td>x</td>
                <td>x</td>
            </tr>
    </table>
</div>

safari test

chrome test

div 1500 px

like image 796
Marco Costa Avatar asked Apr 16 '26 22:04

Marco Costa


2 Answers

Since you are using bootstrap,instead of using styles use the inbuilt classes.

<div class="table table-responsive">
   <table >  //give width styling as you want.
        <tr>
            <td>very large width table with scroll horizontal</td>
            <td>x</td>
            <td>x</td>
            <td>x</td>
        </tr>
   </table>
</div>

This will give you a horizontal scrollbar.

like image 151
Varun Avatar answered Apr 18 '26 12:04

Varun


at first.you should add class name 'table-responsive' to the div element which is the container element of the table.

<div class="table-responsive">
  <table class="table table-bordered table-hover table-condensed small">
  /* table content here */
  </table>
</div>

second. if you want the effect that all content in the table display only on one line without soft wrap.you should add css style to your style sheet with content as below:

th,td{
    /*use this property to disbale soft wrap*/
    white-space: nowrap;
    /*To make extra certain,add this css property*/
    word-break: keep-all;

}
like image 21
user3033075 Avatar answered Apr 18 '26 10:04

user3033075



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!