javascript - Bootstrap table in div horizontal scroll not work - Stack Overflow

In the content, I put a div with a table inside. I need it to scroll horizontally. I've spent hour

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>

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>

Share Improve this question edited Jun 14, 2015 at 15:38 j08691 208k32 gold badges269 silver badges280 bronze badges asked Jun 14, 2015 at 5:55 Marco CostaMarco Costa 371 gold badge2 silver badges9 bronze badges 3
  • You just want to be able to scroll horizontally when the table is wide, ride? Because your code already does that for me. Or am I misunderstanding your question? – SamuelMS Commented Jun 14, 2015 at 5:58
  • It seems to work for me -- jsfiddle/0k9a2h10 -- what problem are you having? If on OS X, know that the default behavior is to not show scrollbars. So you won't see them unless you toggle that setting or add fake scrollbars. With a touchpad, the JSFiddle I linked to scrolls horizontally. – Cymen Commented Jun 14, 2015 at 5:58
  • does not work here, what could be wrong? – Marco Costa Commented Jun 14, 2015 at 15:30
Add a ment  | 

2 Answers 2

Reset to default 6

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.

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;

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743743494a4499578.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信